# mysql统计多个状态
# 1 通过count和if判断来统计
select
COUNT(*) AS total,
COUNT(if( mdt_apply_type='1' ,1,NULL) )as singleDiseasesNum,
COUNT(if( mdt_apply_type='2' ,1,NULL) )as multidisciplinaryNum
from t_mdt_apply_list b WHERE 1=1 AND audit_opinion='3'
1
2
3
4
5
2
3
4
5
# 2 通过sum和if判断来统计
select
COUNT(*) AS total,
SUM(if( mdt_apply_type='1' ,1,0) )as singleDiseasesNum,
SUM(if( mdt_apply_type='2' ,1,0) )as multidisciplinaryNum
from t_mdt_apply_list b WHERE 1=1 AND audit_opinion='3'
1
2
3
4
5
6
2
3
4
5
6