我在sql server中编写了一个查询,如下所示......
SELECT
[AC_NO],part_no,
SUM(CASE WHEN sex='M' THEN 1 ELSE 0 END) as male ,
SUM(CASE when sex='F' THEN 1 ELSE 0 END) as female,
SUM(CASE when sex='o' THEN 1 ELSE 0 END) as other,
SUM(CASE WHEN sex='M' THEN 1 ELSE 0 END) as male
FROM [ALL_ERMS_S1_S2_2014].[dbo].[ALL_MR_ERMS] where ORG_LIST_NO=2 and ac_no=91 and STATUSTYPE='N'
group by ac_no,part_no
order by ac_no,part_no
**ac_no PART_NO male female other total**
91 2 1 0 0 1
91 3 1 1 0 2
91 4 1 1 0 2
91 7 1 1 0 2
91 8 4 2 0 6
我得到的结果如下......
在Part_no col中你可以标记1,5,6缺少b在该部分中所有值都是0.我想在下面...
ac_no PART_NO male female other total
91 1 0 0 0 0
91 2 1 0 0 1
91 3 1 1 0 2
91 4 1 1 0 2
91 5 0 0 0 0
91 6 0 0 0 0
91 7 1 1 0 2
91 8 4 2 0 6
请帮帮我.... 我怎样才能得到这个结果....