I have table with positions
tbl_positions
id position
1 Driver
2 Lobby
3 Support
4 Constructor
and in other table i have users
tbl_workers
id name position status
1 John 2 3
2 Mike 3 2
3 Kate 2 3
4 Andy 1 0
i do request of positions
Without status I select everything with this query .
SELECT p.id, p.position, count(*) FROM tbl_positions as p
inner join tbl_workers as w on w.position=p.id
group by p.id, p.position
But now i need output same query but also considers status, status 2=booked status, 3=placed. I need output like this in single query.
Position booked placed
Driver 0 0
Lobby 0 2
Support 1 0
Constructor 0 0
I tried add WHERE tbl_workers.status IN (2) for booked and WHERE tbl_workers.status IN (3) for placed and it works in two queries, but no luck joining this into one query
Try this: