From f1f31310f76dd6d735b04c3269ad0ad8bdde3b71 Mon Sep 17 00:00:00 2001 From: Adwait Pitkar Date: Tue, 30 Nov 2021 20:30:19 -0500 Subject: [PATCH] Update queries.sql --- queries.sql | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/queries.sql b/queries.sql index 6657755..087d576 100644 --- a/queries.sql +++ b/queries.sql @@ -4,6 +4,15 @@ select * from employee order by salary desc; --- Limit N-1,1 select distinct salary from employee order by salary desc limit 2, 1; +--using DENSE_RANK() +select * from( +select ename, salary, dense_rank() +over(order by salary desc)r from Employee) +where r=&n; +--To find to the 2nd highest sal set n = 2 +--To find 3rd highest sal set n = 3 and so on. + + -- 2> Write a SQL query to find top n records? -- Example: finding top 5 records from employee table select * from employee order by salary desc limit 5;