Interviews4 answers
This is one of the Interview Question Ask in one of MNC Company Interview tbl1 Id Sal 1 1000 2 2000 3 3000 Output Asked Was Id Sal 1 1000 2 3000 3 6000 For fist row Sal Should be same,for second row sum of first and second and third row sum of first,second and third?
4 Answers
select E_ID,sum(Salary) over(order by E_id)AS SALARY from EMP_SALARY
ram rameshPosted Aug 6, 2017, 8:52 PM EDT
select E_ID,sum(Salary) over(order by E_id) from EMP_SALARY
ram rameshPosted Aug 6, 2017, 8:50 PM EDT
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
kakku singhPosted Mar 16, 2017, 9:00 AM EDT
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
Aniket NarvankarPosted Dec 15, 2016, 11:43 PM EST

