SELECT all orders with more than one item and check all items status

后端 未结 2 470
暗喜
暗喜 2021-01-26 09:27

I have 2 tables:

Orders:

Id   |  Status
-----+--------
 1   |      OK
 2   | WAITING
 3   | WAITING
 4   |      OK
 5   |      OK
 6   |      OK
<         


        
2条回答
  •  Happy的楠姐
    2021-01-26 10:04

    select O.id
    from orders O inner join order_details OD
    on O.Id=OD.Order_Id and O.Status='OK' AND OD.Status IN ('S1','S2')
    GROUP BY O.Id
    HAVING count(DISTINCT OD.Id)>1
    

提交回复
热议问题