I've a column that have 15 distinct values. I'd like to count how many there are of a few of them, I've come up with e.g.
select a,COUNT(IFNULL(b != 1,NULL)),COUNT(IFNULL(b != 2,NULL)) from
mytable group by a
select a,SUM(CASE WHEN a = 1 THEN 1 ELSE 0)),SUM(CASE WHEN a = 2 THEN 1 ELSE 0)) from
mytable group by a
What's the best way of doing this ? (note, I need to pivot those values to columns, a simple select a,b,count(*) from mytable where b=1 or b=2 group by a,b; won't do.)