Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
How to find 2nd highest salary
create table sal ( id int, sal float ) insert into sal values(1,100),(2,500),(3,400),(4,200),(5,400),(6,350),(7,350) select * from sal order by sal desc ; with cte as ( select * , dense_rank() over (order by sal desc)dn from sal ) select id, sal from cte where dn = 2 select * , dense_rank() over (order by sal desc)dn from sal
run
|
edit
|
history
|
help
0
text
test
store
test
employee table
Output
Q2_5MIN
SQL Server NULL replacement with dynamic value
Data row generator (good performance, w/o recursive CTE)
BC3TOSQL