I'm using sql server 2012, where I have table [BonusTransactions]
(Id, Author, Bonus)
1 Andrew 5
2 Andrew 2
3 Jim 6
4 Jim 2
5 Jim 15
I need to make query that will return this table with cumulative field for every Author:
(Id, Author, Bonus, TotalBonus)
1 Andrew 5 5 (5)
2 Andrew 2 7 (5+2)
3 Jim 6 6 (6)
4 Jim 2 8 (6 + 2)
5 Jim 15 23 (6 + 2 + 15)
So I tried this query:
SELECT Id, Author, Bonus,
Sum(Bonus) Over (Partition By Author order by Id) as TotalBonus
FROM [dbo].[BonusTransactions]
but it doesn't work: "Incorrect syntax near 'order'."
Also i tried this:
SELECT Id, Author, Bonus,
Sum(Bonus) Over (Partition By Author order by Id ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) as TotalBonus
FROM [dbo].[BonusTransactions]
But in this case intellisense highlights "ROWS BETWEEN" and column names