thử cái này
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)
thử cái này
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)