Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions queries.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down