日期:2014-05-16 浏览次数:20881 次
SELECT dwdm,
sum(iif(hi_Djdm='g1_01',1,0)) as G1_01,
sum(iif(hi_Djdm='g1_02',1,0)) as G1_02,
sum(iif(hi_Djdm='g1_03',1,0)) as G1_03,
sum(iif(hi_Djdm='g2_01',1,0)) as G2_01,
sum(iif(hi_Djdm='g2_02',1,0)) as G2_02,
sum(iif(hi_Djdm='g2_03',1,0)) as G2_03,
sum(iif(hi_Djdm='g3_01',1,0)) as G3_01,
sum(iif(hi_Djdm='g3_02',1,0)) as G3_02,
sum(iif(hi_Djdm='g3_03',1,0)) as G3_03
FROM (
select test1.dwdm,test2.rydm ,test2.Gzdm & '_' & max(test2.Djdm) as hi_Djdm
from test2 inner join test1 on test2.rydm=test1.rydm
group by test1.dwdm,test2.rydm,test2.Gzdm
)
GROUP BY dwdm
dwdm G1_01 G1_02 G1_03 G2_01 G2_02 G2_03 G3_01 G3_02 G3_03 01 0 1 1 0 1 0 1 0 0 02 1 1 0 1 0 0 0 0 0