mysql根据不同状态统计出现的次数

// 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;

猜你喜欢

转载自blog.csdn.net/xiaoxinshuaiga/article/details/83212136