SQL ASSIGNMENTS

#snehal #sheth

snehal sheth Jul 07 2021 · 1 min read
Share this

ASSIGNMENT -9

Q-1.  Write an SQL query to show the top n (say 10) records of a table.

SELECT TOP 8 SALARY FROM WORKERS

Q-2. Write an SQL query to determine the nth (say n=5) highest salary from a table.

SELECT TOP 1 SALARY

FROM (

SELECT DISTINCT TOP 5 SALARY AS SALARY

FROM WORKERS

ORDER BY Salary DESC

) AS WORKERES ORDER BY SALARY ASC;

ASSIGNMENT-10

Q-1. Write an SQL query to determine the 5th highest salary without using TOP or limit method.

SELECT FIRST_NAME, SALARY, RANKING FROM ( SELECT FIRST_NAME, SALARY,

RANK () OVER (

PARTITION BY FIRST_NAME

ORDER BY SALARY DESC

) AS RANKING

FROM WORKERS) AS WORKESS WHERE RANKING = 1;

Q-2. Write an SQL query to fetch the list of employees with the same salary.

Select distinct W.WORKER_ID, W.FIRST_NAME, W.SALARY

from WORKERS W, WORKERS W1

where W.SALARY = W1.SALARY

and W.WORKER_ID != W1.WORKER_ID;

Comments
Read next