【问题标题】:How to get products from order, order entries, and orders status from query如何从订单中获取产品、订单条目、从查询中获取订单状态
【发布时间】:2020-10-02 22:42:48
【问题描述】:

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

  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}

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

【问题讨论】:

    标签: mysql hybris flexible-search


    【解决方案1】:

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

    【讨论】:

    • 那太好了,谢谢。但我也添加了限制,这是我从另一个表中获取的,我可以将它包含在它中,就像从 {top sellproductcomponent} 中选择 {numberOfProducts} 一样。它返回数字(如 10)。所以我可以限制即将到来的值
    • 查看上面我编辑的查询。只需要稍作修改。应该做的伎俩
    • 另外,我认为没有任何方法可以使用 select 语句中的 {top sellproductcomponent} 值来完成您所要求的事情。一个 groovy 脚本可能是实现这一目标的最佳方式。
    猜你喜欢
    • 2020-12-16
    • 1970-01-01
    • 2022-06-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-05-08
    • 1970-01-01
    • 2017-08-26
    相关资源
    最近更新 更多