April 29, 2016
Interview Question
--Get the second highest salary of HR department
select * from #employee1
select * from #department1
;with cte(empname,sal,row)
as
(
select empname,empsal,ROW_NUMBER() OVER (Order by empsal desc) AS RowNumber from #employee1 e
join #department1 d on e.depid=d.depid
where d.depname='HR'
)
select * from cte where row=2
select * from #employee1
select * from #department1
;with cte(empname,sal,row)
as
(
select empname,empsal,ROW_NUMBER() OVER (Order by empsal desc) AS RowNumber from #employee1 e
join #department1 d on e.depid=d.depid
where d.depname='HR'
)
select * from cte where row=2