筛选拆单后订单状态全部为已取消状态的订单有哪些

发布时间 2023-03-27 22:39:01作者: 翎野君

背景

用户下单之后,我们会按照发货仓库进行拆单,即一个父订单可能会对应过个子订单。现在有一个场景需要查询有哪些父订单下的子订单是全部都被取消的,订单的取消状态为99。

筛选拆单后订单状态全部为已取消状态的订单有哪些?

select parent_order_no,t.total_qty, t.99_qty from (
select parent_order_no,count(*) as total_qty,sum(case when order_status = 99 then 1 else 0 end) as 99_qty
from order_main where order_type = 3 
group by parent_order_no
) t
where t.total_qty = t.99_qty

  

本篇文章如有帮助到您,请给「翎野君」点个赞,感谢您的支持。

首发链接:https://www.cnblogs.com/lingyejun/p/17263313.html