这是我的 table
create table #t(id int, amt int)
insert into #t values(1, 40), (1, 20), (1, 10), (2, 100), (2, 120), (2, 400)
我需要这样的输出!
id amt
1 70
1 70
1 70
2 620
2 620
2 620
我试过了
SELECT
id, SUM(amt)
FROM
#t
GROUP BY
id
最佳答案
试试这个!
select id,sum(amt) over(partition by id) as amt from #t
关于sql - 查询 SQL Server 时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21723886/