有个语句:
select a.* from
((select 1 as id,cSex
,count(case when gj='中国' then '' end) as 中国
,count(case when gj='美国' then '' end) as 美国
,count(case when gj='韩国' then '' end) as 韩国
,count(case when gj='意大利' then '' end) as 意大利
From
(select a.iHumanID,a.cHumanName,a.cSex,b.[Name] as gj From Human a left outer join gj b
on a.gjID=b.GJid) a group by cSex)
union
--求合计
(select 2 as id,'' as cSex,
count(case when gj='中国' then '' end) as 中国
,count(case when gj='美国' then '' end) as 美国
,count(case when gj='韩国' then '' end) as 韩国
,count(case when gj='意大利' then '' end) as 意大利
From
(select a.iHumanID,a.cHumanName,a.cSex,b.[Name] as gj From Human a left outer join gj b
on a.gjID=b.GJid) a)) a