方案一
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 其他条件
当然也还有别的方法:
1、沉到业务中取处理,拆分SQL
2、抽取公用统计属性,建立冗余表