首页 > 解决方案 > 如何从订单中获取产品、订单条目、从查询中获取订单状态

问题描述

我准备了一个灵活的搜索查询。在这里,我开发了一个条件,如:

  1. 订单状态在订单中完成

  2. 以及按顺序出现的订单条目

  3. 获取 orderentries 中的产品

为此我写了一个查询

select {p.pk} from {
  order as o 
  join OrderStatus as os on {os.pk}={o.status}
  join orderentry as oe on{oe.order}={o.pk}
  join product as p on {oe.product}={p.pk}
}
where {os.code}='COMPLETED' 
AND {o.date}>'2020-08-16 00:00:00.000' AND{o.date}<'2020-09-30 00:00:00.000' 
group by{p.pk} order by count({oe.pk}) desc limit 10

在这个查询中,我想要的是我想获取所有产品信息,比如

select * from Product}

如何修改此查询获取所有产品?

标签: mysqlhybrisflexible-search

解决方案


您可以使用子选择来执行此操作。您在上面发布的第一个查询将是子选择。您只需添加另一个选择即可获取子选择中返回的所有 PK 的产品信息。

select * from {Product as prod} where {prod.pk} in 
({{ 
  select 
    top 10 {p.pk} 
  from 
    {
      Order as o join 
      OrderStatus as os on {os.pk} = {o.status} join 
      OrderEntry as oe on {oe.order} = {o.pk} join 
      Product as p on {oe.product} = {p.pk}
    }
  where 
    {os.code} = 'COMPLETED' and 
    {o.date} > '2020-08-16 00:00:00.000' and 
    {o.date} < '2020-09-30 00:00:00.000'
  group by {p.pk} 
  order by count({oe.pk}) desc
}})

推荐阅读