select E_ID,sum(Salary) over(order by E_id) from EMP_SALARY
select E_ID,sum(Salary) over(order by E_id)AS SALARY from EMP_SALARY
The query for above question: Select a.Id,(Case when a.Id <> 0 then(Select Sum(Sal) from tbl1 b where b.Id <= a.Id) end) as Sal from tbl1 a order by a.Id
declare @tbl Table (Id int,Sal numeric(10)) INSERT INTO @tbl (Id,Sal) VALUES (1,1000); INSERT INTO @tbl (Id,Sal) VALUES (2,2000); INSERT INTO @tbl (Id,Sal) VALUES (3,3000); Select a.Id,(Case when a.Id <> 0 then(Select Sum(Sal) from @tbl b where b.Id <= a.Id) end) as Sal from @tbl a order by a.Id