16. Nth highest salary (Top 50 SQL Interview Questions) | GeeksforGeeks

16. Nth highest salary (Top 50 SQL Interview Questions) | GeeksforGeeks

GeeksforGeeks

4 года назад

70,777 Просмотров

Ссылки и html тэги не поддерживаются


Комментарии:

@maniganesh1403
@maniganesh1403 - 28.10.2023 13:10

SELECT DISTINCT Salary as EighthDistinctHighestSalary
FROM Employee
ORDER BY Salary DESC
LIMIT 1 OFFSET 7;
by changing the offer we can obtain the nth number

Ответить
@farhanAli-yo6vv
@farhanAli-yo6vv - 18.09.2023 11:45

This fool guy is teaching us with rownum, rownum actually does not work in mysql

Ответить
@aakashjadhav6242
@aakashjadhav6242 - 09.04.2023 21:20

with salary_Details as (
select emp_name, emp_sal, dense_rank () over ( order by emp_sal desc) as rank from employee)
select * from salary_Details
where rank = 3;

Ответить
@prajjwaljaiswal3419
@prajjwaljaiswal3419 - 19.06.2022 18:58

alternative of rownum in MySQl ?

Ответить
@vishnuvamshi4645
@vishnuvamshi4645 - 05.05.2022 22:24

facing problem please provide the solution the screen is showing like this

Incorrect syntax near the keyword 'where'.

select distinct salary from empdetail order by salary desc
where rownum<=3;
minus
select distinct salary from empdetail order by salary desc
where rownum<=2;

Ответить
@vishnuvamshi4645
@vishnuvamshi4645 - 05.05.2022 22:21

copy and paste the command in the description section so that it will be helpful

Ответить
@shubhambhardwaj2593
@shubhambhardwaj2593 - 12.04.2022 02:27

Just order by desc and use LIMIT 1 and OFFSET N?

Ответить
@shraddhadhakad1154
@shraddhadhakad1154 - 10.03.2022 04:39

Explained well 💫💫💫

Ответить
@ridwanmugdha7623
@ridwanmugdha7623 - 02.03.2022 12:56

SELECT * FROM Employee WHERE sal =
(
SELECT MIN(sal) FROM Employee
WHERE sal IN (
SELECT DISTINCT TOP N
sal FROM Employee
ORDER BY sal DESC
)
)

Ответить
@ashrutsharma2442
@ashrutsharma2442 - 28.09.2021 15:35

Limit N,N-1; ??

Ответить
@raghavanrags7
@raghavanrags7 - 22.05.2021 13:03

Why can we directly use the query without like an inline kind of query..i mean why cant we use select distinct sal from emp order by sal desc where rownum<=3 minus select distinct sal from emp order by sal desc where rownum<=2;

Ответить
@Kavishkhullar
@Kavishkhullar - 04.05.2021 02:57

can't we directly use rownum=3 in the 1st query?

Ответить
@tanvirkaur5013
@tanvirkaur5013 - 12.04.2021 16:59

Why the only thing i can focus on is his 'yanth' highest salary nd his strong tamil accent.

Ответить
@ankitshrivastava1772
@ankitshrivastava1772 - 16.02.2021 06:01

getting error minus identifier is not valid at this position in the query,

SELECT * FROM(SELECT DISTINCT MARKS FROM tbl_studentData order by MARKS desc )
where rownum <=3

minus

SELECT * FROM(SELECT DISTINCT MARKS FROM tbl_studentData order by MARKS desc )
where rownum <=2

Ответить
@kirankumarreddy3170
@kirankumarreddy3170 - 15.02.2021 13:03

Recommend

Ответить
@DonBhai006
@DonBhai006 - 17.01.2021 21:44

Are these questions are good enough for 2 years of experiance employee in sql

Ответить
@lakshmiprasanna179
@lakshmiprasanna179 - 07.11.2020 04:42

We can use this "Select * from emp( Select rownum r, distinct(sal) from emp order by desc) where r = 3;"

Ответить
@animeprofiles2077
@animeprofiles2077 - 19.10.2020 13:48

Man u gave such a general startegy 👍 so awesome
For mysql users
U can use TOP clause in place of rownum

Ответить
@arunvignesh1942
@arunvignesh1942 - 19.10.2020 07:56

select min(sal) from(select distinct sal from emp order by sal desc)
where rownum<=3;
without minus we can use it in this way

Ответить
@Iwitrag
@Iwitrag - 12.10.2020 10:22

I would wrap it into another sub-query and assign rownum alias... then in outer query you could just check for equals

Ответить
@divakarkumarjha1171
@divakarkumarjha1171 - 13.09.2020 07:46

Awesome explained sir

Ответить
@abhipsajena1083
@abhipsajena1083 - 04.09.2020 09:12

Can we use NOT IN instead of MINUS?

Ответить
@dineshpandey5008
@dineshpandey5008 - 18.07.2020 18:13

Greate sir, it can be done by using = operator instead of minus operator.

Ответить
@sezgin9427
@sezgin9427 - 13.05.2020 09:38

this is a great content, have been looking such a content for days

Ответить
@gauravbaser3559
@gauravbaser3559 - 05.04.2020 13:05

what's the difference between select * from (select distinct Sal from Emp order by sal desc) vs select distinct Sal from Emp order by sal desc???

Ответить
@MegaEbenezar
@MegaEbenezar - 12.11.2019 07:32

We can use the below query
select max(sal) from(select distinct Sal from Emp order by sal desc) where rownum<= 3

Ответить
@sahiltikku6970
@sahiltikku6970 - 03.11.2019 11:56

Thanks

Ответить
@kamalm1806
@kamalm1806 - 11.10.2019 13:19

What's the difference between highest salary and nth highest salary?

Ответить
@anjalishah2907
@anjalishah2907 - 10.10.2019 20:40

Any online good platform for sql command ?

Ответить
@praveenj3112
@praveenj3112 - 09.10.2019 19:03

It's very helpful

Ответить
@praveenj3112
@praveenj3112 - 09.10.2019 19:03

Thanks

Ответить
@andrebemantoro6559
@andrebemantoro6559 - 09.10.2019 17:11

improve the audio quality please

Ответить
@vamsiksk912
@vamsiksk912 - 09.10.2019 16:39

Can't we write rowno=3

Ответить