select id,count(id),flag from mytable group by id
ID | flag 1 | 0 2 | 0 3 | 1 2 | 0 1 | 0 3 | 1 2 | 0 1 | 1 2 | 1 3 | 1
ID | Count Flag O | Count Flag 1 1 | 2 | 1 2 | 3 | 1 3 | 0 | 3
Select ID, SUM(case when flag = 0 then 1 else 0 end) as [Count Flag O], SUM(case when flag = 1 then 1 else 0 end) as [Count Flag 1] from test group by ID
SELECT ID, SUM(IF(`flag` = 0, 1, 0)) 'Count Flag 0', SUM(IF(`flag` = 1, 1, 0)) 'Count Flag 1' FROM MyTable GROUP BY ID;
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)