这是我之前写的
select KT_CPGL.fCPWCSJ as fCPWCSJ,
(select COUNT(1) from KT_CPGL a where a.fCPZT='合格' group by KT_CPGL.fCPWCSJ ) as row1,
(select COUNT(1) from KT_CPGL a where a.fCPZT='不合格' group by KT_CPGL.fCPWCSJ) as row2
from KT_CPGL KT_CPGL
group by KT_CPGL.fCPWCSJ
没什么区别,我改成
select KT_CPGL.fCPWCSJ as fCPWCSJ, sum(case when KT_CPGL.fCPZT='合格' then 1 else 0 end) as fGoodNum, sum(case when KT_CPGL.fCPZT='不合格' then 1 else 0 end) as fBadNum, count(a) as fTotleNum
from KT_CPGL KT_CPGL
group by KT_CPGL.fCPWCSJ
可以查但是关系别名不能改 用的是bex5 3.6。