I have 3 tables:
- Users (id, name)
- Orders (id, userId)
- Orders_Items (id, orderId, status)
First, I wanted to list all users with the corresponding number of such orders:
It's easy, I do "select name, count (id) from users, orders, where users.id = orders.userId group by name".
Now I would like to additionally filter this data to show only users with orders who have items with status = "unprocessed." I am not sure how to collect data from two tables. In the end, I want to get data like:
- (A is not shown, there is no order with any element having status = unprocessed)
- B, 3 orders (2 orders do not have an item with status = unprocessed).
Thank!