select a.单位,isnull(九十分,0) as '90',isnull(八十分,0) as '80',isnull(七十分,0) as '70',isnull(六十分,0) as '60',isnull(五十分,0) as '50' from
((((select 单位,count(*) as 九十分 from lx where 分数=90 group by 单位) a full join
(select 单位,count(*) as 八十分 from lx where 分数=80 group by 单位) b on a.单位=b.单位) full join
(select 单位,count(*) as 七十分 from lx where 分数=70 group by 单位) c on a.单位=c.单位) full join
(select 单位,count(*) as 六十分 from lx where 分数=60 group by 单位) d on a.单位=d.单位) full join
(select 单位,count(*) as 五十分 from lx where 分数=50 group by 单位) e on a.单位=e.单位
union
select a.单位,isnull(九十分,0) as '90',isnull(八十分,0) as '80',isnull(七十分,0) as '70',isnull(六十分,0) as '60',isnull(五十分,0) as '50' from
((((select 'A+B' as 单位,count(*) as 九十分 from lx where 分数=90 and (单位='A' or 单位='B') ) a full join
(select 'A+B' as 单位,count(*) as 八十分 from lx where 分数=80 and (单位='A' or 单位='B') ) b on a.单位=b.单位) full join
(select 'A+B' as 单位,count(*) as 七十分 from lx where 分数=70 and (单位='A' or 单位='B') ) c on a.单位=c.单位) full join
(select 'A+B' as 单位,count(*) as 六十分 from lx where 分数=60 and (单位='A' or 单位='B') ) d on a.单位=d.单位) full join
(select 'A+B' as 单位,count(*) as 五十分 from lx where 分数=50 and (单位='A' or 单位='B') ) e on a.单位=e.单位
union
select a.单位,isnull(九十分,0) as '90',isnull(八十分,0) as '80',isnull(七十分,0) as '70',isnull(六十分,0) as '60',isnull(五十分,0) as '50' from
((((select 'A+B+C' as 单位,count(*) as 九十分 from lx where 分数=90 ) a full join
(select 'A+B+C' as 单位,count(*) as 八十分 from lx where 分数=80 ) b on a.单位=b.单位) full join
(select 'A+B+C' as 单位,count(*) as 七十分 from lx where 分数=70 ) c on a.单位=c.单位) full join
(select 'A+B+C' as 单位,count(*) as 六十分 from lx where 分数=60 ) d on a.单位=d.单位) full join
(select 'A+B+C' as 单位,count(*) as 五十分 from lx where 分数=50 ) e on a.单位=e.单位
在查询分析器中测试正确,满足楼主的要求。lx 为楼主的表。