如何从订单中获取产品,订单条目以及从查询中获取订单状态

时间:2020-10-02 22:42:48

标签: mysql hybris flexible-search

我准备了一个灵活的搜索查询。在这里,我出现了类似这样的情况:

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

  2. 以及订单中显示的订单条目

  3. 获取订单项中的产品

为此,我写了一个查询

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}

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

1 个答案:

答案 0 :(得分:0)

您可以使用子选择来执行此操作。您在上面发布的第一个查询将是子查询。您只需要添加另一个选择即可获取该子选择中返回的所有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
}})