I have a list of orders, I need to find which ones occur with code 47 more than once with different users. For example:
ORDER_ID CODE USER 111 47 1 111 47 2 222 47 1 333 47 1 333 47 2 444 47 1
The expected result is 111 and 333.
How can I accomplish this?
Regards
Advertisement
Answer
I think you want aggregation and having
:
select order_id from orders o where code = 47 group by order_id having min(user) <> max(user);
You can also express the having
as:
having count(distinct user) >= 2