I have two tables (lets call them cases and users) structured something like this: Cases
ID|status |user_id
__|____________|_______
1 |Open |6
2 |Closed |9
3 |Incomplete |9
Users:
ID|
__|_____
6|
9|
I would like to select a count for the id as well as a count for each one of the status fields.
Currently I have tried:
SELECT COUNT(c.id), COUNT(
(SELECT status from cases where status = 'Open')),
COUNT(
(SELECT status from cases where status = 'Closed')),
COUNT(
(SELECT status from cases where status = 'Incomplete'))
FROM cases as c
JOIN users as u on u.id = c.user_id
I am getting an error of query returning more than one row.
This is what I am trying to achieve
ID| Open | Closed | Incomplete |user_id
__|______|________|____________|__________
2|0 |1 |1 |9
RECAP: A count for each user id that counts how many id's, and a count for each status.