方案一

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、抽取公用统计属性,建立冗余表

 

showtooltip

相关文章:

  • 2021-08-29
  • 2021-10-11
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-03-10
  • 2022-12-23
  • 2022-12-23
  • 2021-08-26
  • 2021-12-10
  • 2021-10-31
  • 2021-11-06
相关资源
相似解决方案