现在我在我的SQL查询中使用临时表,但我想使用Partition By函数.
我的临时表查询如下:
drop table #Temp;
create table #Temp
(
NAME varchar(50),
EMPID varchar(50),
SS MONEY,
PP MONEY
);
insert into #Temp
select * From
(
select
p1.NAME,
p1.EMPID,
case when p1.AmtPayer = 'SELF' then sum(p1.Salary) else 0 end as S,
case when p1.AmtPayer = 'MANAGER' then sum(p1.Salary) else 0 end as P
from Candidate p1
group by p1.Name, p1.EMPID, p1.AmtPayer
) as P;
select
t.NAME,
t.EMPID,
sum(t.SS) as 'SELF PAID',
sum(t.PP) as 'PARTY PAID'
from #Temp t
group by …Run Code Online (Sandbox Code Playgroud)