SQL QUERY QUESTIONS - prkirankumar/interview-preparation GitHub Wiki
SELECT DISTINCT salary FROM table ORDER BY salary DESC LIMIT 1 OFFSET 1
with ordered_salary as
(
SELECT name, salary, ROW_NUMBER() OVER(ORDER BY salary DESC) rn
FROM salary_table
)
select name, salary
from ordered_salary
where rn = 5
select dept, max(salary) from Employee
group by dept
Using Windows Function to find nth highest salary department wise (Here Partition by will work like grouping)
select * from (select *, ROW_NUMBER() Over(partition by dept order by salary desc) as highest_payed
from Employee)
where highest_payed = 1
Select * from (Select *,
ROW_NUMBER() OVER(order by salary) as rn from Employee)
where rn % 2 =0
select * from (
select emp_name,
ROW_NUMBER() OVER(PARTITION by emp_name) rn
from Employee)
where rn > 1
select emp_name, count(*)
from employee
group by emp_name
HAVING count(*) > 1
select * from Customers
limit 1
offset 3
WITH CTE AS
(
SELECT *, row_number() OVER(ORDER BY pk of that table) as rn, count(*) OVER () AS total_rows
FROM table1)
SELECT *
FROM CTE
WHERE rn <=n OR rn > total_rows - m