I have this table, in the left there is the sample input table and on the right desired output
How to calculate the number of status per empid basis using SQL on MySQL.
2
Common conditional aggregation:
SELECT `emp-id`, SUM(status = 'Open') `Open`, SUM(status = 'Pending') `Pending`, SUM(status = 'Resolved') `Resolved` FROM source_table GROUP BY 1;
Try something like this:
SELECT empid, COUNT(CASE WHEN status = 'Open' THEN 1 END) `open`, COUNT(CASE WHEN status = 'Pending' THEN 1 END) `pending`, COUNT(CASE WHEN status = 'Resolved' THEN 1 END) `resolved` FROM sampletable GROUP BY empid;
Goodle for "pivot mySQL" for other solutions.
Click here to cancel reply.
2
Answers
Common conditional aggregation:
Try something like this:
Goodle for "pivot mySQL" for other solutions.