这是我的输入表
Create table #table1(id int, fn varchar(20), startdate varchar(20), id1 varcahr, salary int)
insert #table1
select 1, 'Joe', '2019-01-01', 'A', 100
union select 1, 'Joe', '2019-01-01', 'B',200
union select 1, 'Joe', '2019-01-05', 'D',400
union select 1, 'Joe', '2019-01-06', 'E',500
union select 2, 'john', '2019-01-05', 'F',250
union select 2, 'john', '2019-01-05', 'F',250
union select 2, 'john', '2019-01-06', 'G',200
union select 2, 'john', '2019-01-06', 'H',230
union select 2, 'john', '2019-01-07', 'I',310
但是我需要类似的输出 按ID,FN,开始日期,薪水分组,并在新列的总计中获得总计
答案 0 :(得分:0)
您可以使用sum()
的窗口版本。
SELECT id,
fn,
startdate,
id1,
salary,
sum(salary) OVER (PARTITION BY id,
fn,
startdate) total
FROM #table1;