在同一个sql语句中,统计不同条件的Count数量

方法一:

select id,
count(case when 属性 in (1,2) then 1 else 0 end) as sum1,
count(case when  属性 in (3) then 1 else 0 end) as sum2,
sum(case when  属性 in (4,5) then 1 else 0 end) as sum3
from 表名
group by id

方法二:

SELECT   
count( * ) AS num,  
count(if(字段=1,true,null)) AS sum1,   
count(if字段=2,true,null)) AS sum2   
FROM 表名 
WHERE  其他条件