create table pc(dept int , eq int , code int)
--说明 dept 部门编号; eq 设备类型编号 1 笔记本 2 台式机 ;code 型号编码
insert into pc values(1,1,1)
insert into pc values(1,2,1)
insert into pc values(2,1,1)
insert into pc values(3,1,1)
insert into pc values(3,1,1)
insert into pc values(3,1,1)
select dept ,sum(case eid when 1 then pcsum else 0 end) as '笔记本数量',sum(case eid when 2 then pcsum else 0 end) as '台式机数量',sum(case eid when 3 then pcsum else 0 end) as '总数量' from
(select dept,case eq when 1 then eq when 2 then eq else 3 end as eid, count(*) as 'pcsum' from pc group by dept ,eq with rollup)
as tab where dept is not null group by dept
select 科室,(select sun(设备类型) from 表名 where 科室=a.科室),(select sun(设备类型) from 表名 where 科室=a.科室 and 科室='笔记本'),(select sun(设备类型) from 表名 where 科室=a.科室 and 科室='台式机'), from 表名 as a group by 科室
试一下,我没环境,不行再探讨。