Mysql
 sql >> Database >  >> RDS >> Mysql

Aggregato condizionale con clausola Group By

prova questo

 SELECT concat(id1,'-', id2) `key`, count(*) , 
 sum( case when category = 1 then 1 else 0 end) category1count , 
 sum( case when category = 2 then 1 else 0 end) category2count
 FROM table1 
 GROUP BY concat(id1,'-', id2)

DEMO QUI