Interviews6 answers
This is one of the Interview Question Ask in one of MNC Company Interviewt bl1 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.
6 Answers
create database company
go
use company
create table tbl1
(
Id INT Primary Key Identity,
Sal INT(50)
)
GO
INSERT INTO tbl1 Values((1,1000),(2,2000),(3,3000))
select id, sum(sal) over(order by id) as sal_ from emp
Sweet ChimePosted Sep 6, 2018, 6:52 AM EDT
Select a.id,a.salary,sum(b.salary) as salary from table a
cross join table b
where b.id<=a.id
group by a.id,a.salary
Sai ReddyPosted May 27, 2018, 8:22 PM EDT
Select a.id,a.salary,sum(b.salary) as salary from table a
cross join table b
where b.id<=a.id
group by a.id,a.salary
Sai ReddyPosted May 27, 2018, 8:22 PM EDT
select Id,sum(Sal) over(order by Id)AS SAL from @tbl
Sushobhit RamanPosted Nov 6, 2017, 7:42 PM EST
select Id,sum(Sal) over(order by Id)AS SAL from @tbl
Sushobhit RamanPosted Nov 6, 2017, 7:42 PM EST
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:42 PM EST


