// case when 的使用
select userid, sum(case when status =1 then 1 else 0 end) as '1',
sum(case when status =2 then 1 else 0 end) as '2',
sum(case when status =3 then 1 else 0 end) as '3'
from user group by userid;
// case when 的使用
select userid, sum(case when status =1 then 1 else 0 end) as '1',
sum(case when status =2 then 1 else 0 end) as '2',
sum(case when status =3 then 1 else 0 end) as '3'
from user group by userid;