I have 2 tables:
Orders:
Id | Status
-----+--------
1 | OK
2 | WAITING
3 | WAITING
4 | OK
5 | OK
6 | OK
<
SELECT O.Id
FROM Orders O
JOIN Order_details OD ON O.Id=OD.Order_Id
WHERE O.Status='OK'
GROUP BY O.Id
HAVING count(DISTINCT OD.Id)>1
AND SUM(CASE WHEN OD.Status NOT IN ('S1','S2')
THEN 1
ELSE 0
END) = 0
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