背景
用户下单之后,我们会按照发货仓库进行拆单,即一个父订单可能会对应过个子订单。现在有一个场景需要查询有哪些父订单下的子订单是全部都被取消的,订单的取消状态为99。
筛选拆单后订单状态全部为已取消状态的订单有哪些?
代码语言:javascript复制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