Can you have a look at the code given below:
USE AdventureWorks2008R2;
GO
SELECT SalesOrderID, SUM(LineTotal) AS SubTotal
FROM Sales.SalesOrderDetail AS sod
GROUP BY SalesOrderID
ORDER BY SalesOrderID;
Link is:
http://msdn.microsoft.com/en-us/library/ms177673.aspx[
^]
Examples using group by clause.
Hope this will help you.
I tested your code:
SELECT [Year], sum(Income) as [Annual Income] FROM dbo.Table_1 GROUP BY [Year]
Out put is:
2008 2500
2009 2000
So no problem with it.
You are absolutely correct.
Updated Answer:
Please check the code given below:
DECLARE @TableVar TABLE
(
YearWise BIGINT,
TotalAmount BIGINT
)
INSERT INTO @TableVar
SELECT [Year], sum(Income) as [Annual Income] FROM dbo.Table_1 GROUP BY [Year]
SELECT YearWise,(SELECT SUM(TotalAmount)
FROM @TableVar
WHERE TotalAmount>=t.TotalAmount) AS CumulativeSum
FROM @TableVar t
Output:
YearWise CumulativeSum
2008 2500
2009 4500
It will work fine.
Hope this will help you.
Cheers man..