请问PIVOT 转表
unitid applynum state
6236111
6236111
6236112
6236110
6236113
SELECT UnitiD,[0] 未审核,[1] 已通过,[2] 未通过
FROM FormationApply f
PIVOT(SUM(f.ApplyNum) FOR f.State IN ([0],[1],[2])) AS pvt
ORDER BY unitid
unitid 未审核 已通过 未通过
62361NULL1NULL
62361NULL1NULL
62361NULLNULL1
623611NULLNULL
62361NULLNULLNULL
select UnitiD,
[0] 未审核,
[1] 已通过,
[2] 未通过
from (select unitid,applynum,[state] from FormationApply) f
pivot(count(ApplyNum) FOR [State] IN ([0],[1],[2])) AS pvt
order by unitid