create table newtest (
Section varchar(50),
Department varchar(50),
salesamount float
)
Insert into newtest
select 'Sec1','IT',2000.89 union
select 'Sec1','IT',1000.89 union
select 'Sec1','IT',3000.89 union
select 'Sec1','BPO',2000.89 union
select 'Sec2','BPO',5000.89 union
select 'Sec2','IT',2700.89 union
select 'Sec2','BPO',2000.89 union
select 'Sec3','IT',6000.89 union
select 'Sec3','IT',2000.89 union
select 'Sec3','BPO',9000.89 union
select 'Sec4','IT',2000.89 union
select 'Sec4','BPO',6000.89 union
select 'Sec3','BPO',1000.89 union
select 'Sec4','IT',3000.89
select * from newtest
Select section, department, SUM(salesamount)
from newtest
Group by Section, Department
--使用数据透视表
select [Sec1] AS Sec1BPO,
[Sec2] AS Sec2BPO,
[Sec3] AS Sec3BPO,
[Sec4] AS Sec4BPO,
[Sec1] AS Sec1IT,
[Sec2] AS Sec2IT,
[Sec3] AS Sec3IT,
[Sec4] AS Sec4IT
from (select Section, Department, salesamount
from newtest) as Sourcetable
PIVOT( SUM([salesamount])
FOR [Section] IN ([Sec1],[Sec2],[Sec3],[Sec4]) ) AS Pivottable
ORDER BY Department
请帮我解决这个问题...当执行上面的代码时,我得到了以下结果
Sec1BPO Sec2BPO Sec3BPO Sec4BPO Sec1IT Sec2IT Sec3IT Sec4IT
-------------------------------------------------------------------------
2000.89 7001.78 10001.78 6000.89 2000.89 7001.78 10001.78 6000.89
6002.67 2700.89 8001.78 5001.78 6002.67 2700.89 8001.78 5001.78
但是我需要作为一个。
Sec1BPO Sec2BPO Sec3BPO Sec4BPO Sec1IT Sec2IT Sec3IT Sec4IT
-----------------------------------------------------------------------
2000.89 7001.78 10001.78 6000.89 6002.67 2700.89 8001.78 5001.78
请帮我获得所需的结果。