SQL Interview Question - Find Nth Highest Salary | LeetCode

preview_player
ะŸะพะบะฐะทะฐั‚ัŒ ะพะฟะธัะฐะฝะธะต
๐–๐š๐ง๐ญ ๐ญ๐จ ๐Œ๐š๐ฌ๐ญ๐ž๐ซ ๐’๐๐‹? ๐‹๐ž๐š๐ซ๐ง ๐’๐๐‹ ๐ญ๐ก๐ž ๐ซ๐ข๐ ๐ก๐ญ ๐ฐ๐š๐ฒ ๐ญ๐ก๐ซ๐จ๐ฎ๐ ๐ก ๐ญ๐ก๐ž ๐ฆ๐จ๐ฌ๐ญ ๐ฌ๐จ๐ฎ๐ ๐ก๐ญ ๐š๐Ÿ๐ญ๐ž๐ซ ๐œ๐จ๐ฎ๐ซ๐ฌ๐ž - ๐’๐๐‹ ๐‚๐ก๐š๐ฆ๐ฉ๐ข๐จ๐ง๐ฌ ๐๐ซ๐จ๐ ๐ซ๐š๐ฆ ๐›๐ฒ ๐’๐ฎ๐ฆ๐ข๐ญ ๐’๐ข๐ซ!

"๐€ 8 ๐ฐ๐ž๐ž๐ค ๐๐ซ๐จ๐ ๐ซ๐š๐ฆ ๐๐ž๐ฌ๐ข๐ ๐ง๐ž๐ ๐ญ๐จ ๐ก๐ž๐ฅ๐ฉ ๐ฒ๐จ๐ฎ ๐œ๐ซ๐š๐œ๐ค ๐ญ๐ก๐ž ๐ข๐ง๐ญ๐ž๐ซ๐ฏ๐ข๐ž๐ฐ๐ฌ ๐จ๐Ÿ ๐ญ๐จ๐ฉ ๐ฉ๐ซ๐จ๐๐ฎ๐œ๐ญ ๐›๐š๐ฌ๐ž๐ ๐œ๐จ๐ฆ๐ฉ๐š๐ง๐ข๐ž๐ฌ ๐›๐ฒ ๐๐ž๐ฏ๐ž๐ฅ๐จ๐ฉ๐ข๐ง๐  ๐š ๐ญ๐ก๐จ๐ฎ๐ ๐ก๐ญ ๐ฉ๐ซ๐จ๐œ๐ž๐ฌ๐ฌ ๐š๐ง๐ ๐š๐ง ๐š๐ฉ๐ฉ๐ซ๐จ๐š๐œ๐ก ๐ญ๐จ ๐ฌ๐จ๐ฅ๐ฏ๐ž ๐š๐ง ๐ฎ๐ง๐ฌ๐ž๐ž๐ง ๐๐ซ๐จ๐›๐ฅ๐ž๐ฆ."

๐‡๐ž๐ซ๐ž ๐ข๐ฌ ๐ก๐จ๐ฐ ๐ฒ๐จ๐ฎ ๐œ๐š๐ง ๐ซ๐ž๐ ๐ข๐ฌ๐ญ๐ž๐ซ ๐Ÿ๐จ๐ซ ๐ญ๐ก๐ž ๐๐ซ๐จ๐ ๐ซ๐š๐ฆ -

๐–๐š๐ง๐ญ ๐ญ๐จ ๐ฅ๐ž๐š๐ซ๐ง ๐๐ข๐  ๐ƒ๐š๐ญ๐š ๐›๐ฒ ๐’๐ฎ๐ฆ๐ข๐ญ ๐’๐ข๐ซ?
๐œ๐ก๐ž๐œ๐ค๐จ๐ฎ๐ญ ๐ญ๐ก๐ž ๐›๐ข๐  ๐๐š๐ญ๐š ๐œ๐จ๐ฎ๐ซ๐ฌ๐ž ๐๐ž๐ญ๐š๐ข๐ฅ๐ฌ

I have trained over 20,000+ professionals in the field of Data Engineering in the last 5 years.

SQL Interview Question - Find Nth Highest Salary | LeetCode

Do Like, Comment & Subscribe ..

๐—๐—ผ๐—ถ๐—ป ๐—บ๐—ฒ ๐—ผ๐—ป ๐—ฆ๐—ผ๐—ฐ๐—ถ๐—ฎ๐—น ๐— ๐—ฒ๐—ฑ๐—ถ๐—ฎ:๐Ÿ”ฅ

In this video, we will solve SQL question on LeetCode. LeetCode is an excellent platform for practicing SQL Queries. The SQL Questions on LeetCode are framed pretty similar to how they are asked on SQL Interviews hence solving SQL questions on LeetCode can give you a good hands on experience on solving real world SQL questions.

Find the nth highest Salary is a very frequently asked SQL Interview question.

#SQL #RDBMS #database #bigdata #dataengineering
ะ ะตะบะพะผะตะฝะดะฐั†ะธะธ ะฟะพ ั‚ะตะผะต
ะšะพะผะผะตะฝั‚ะฐั€ะธะธ
ะะฒั‚ะพั€

learnt new concepts : isNull & offset, also how to approach a problem in multiple ways, thank you very much sir :)

arunsundar
ะะฒั‚ะพั€

Very well explained sir..
The way you explain things ans then give the solution actually prepares our way to think logically about the problems
Thanks a lot.
Please come up with more learnings

sayantansarbadhikary
ะะฒั‚ะพั€

For a non IT data analyst aspirant like me, this was a wonderful session. Each and every thing explained concept is clear

ashishranjan
ะะฒั‚ะพั€

Thank you thank you so much, i understand from you rvideo from one go, really amazing sir you are, thanks a lot, and keep moving in this era ๐Ÿ˜Žโค

rawatbobby
ะะฒั‚ะพั€

Hello sir, Can you please share tips to solve this problem statement ?

There's a grocery store sales transaction table with columns Tnx ID, customer ID, product ID, Date of Tnx, quantity, price. Every sales transaction that happens at the store, gets stored in this table. The store also has a customers table with columns Customer ID, Customer Name, Age, Gender, and Locality.
Write an SQL query to find the name and locality of the customer who purchased the highest number of items in the month of Octโ€™21.

MAYANKKUMAR-kgkc
ะะฒั‚ะพั€

Thanks for explaining multiple approaches.
it seems IFNULL() not working in oracle

mallikarjunpatil
ะะฒั‚ะพั€

My Solution:

select case when max(rn) = 1 then null else salary end as SecondHighestSalary
from (select salary, rank() over( order by salary desc) as rn from Employe)a
where rn = 2

pratiksawalkar
ะะฒั‚ะพั€

Make video on
MySQL performance tuning

ashitosh
ะะฒั‚ะพั€

Thank you Sir for clearing the concept

pranutabedru
ะะฒั‚ะพั€

Thanks for your videos.They are quite good. I just feel I the offset solution will not work. As you don't know beforehand the number of distinct values that will return and dependending on that you have to provide the offset count.

arunavabiswas
ะะฒั‚ะพั€

Thanks sir.. approaches are really interesting... but i think oracle dont have IFNULL feature .. not sure how to get null with 3rd approach

ayushsen
ะะฒั‚ะพั€

I am looking for SQL guidanceโ€ฆ Do you have SQL live course ?

sumibits
ะะฒั‚ะพั€

Can you give your solution. ..sql query txt file as well.. Or can post it on your Github and share the link

sukanyaiyer
ะะฒั‚ะพั€

Instead of limit 1 offset 1, can not we do limit 1, 1

ashishranjan
ะะฒั‚ะพั€

Advance Version - Find n ( eg 10 ) highest salary without order by clause..

SahilGupta-gyey
ะะฒั‚ะพั€

In LC Ques no-177 where we've to write solution for Nth highest salary, if we use limit and offset concept then we've to use offset (N-1) but it shows syntax error when we use minus operator. What to do in this case??

mohammedasif
ะะฒั‚ะพั€

WITH cte AS (
SELECT
salary,
DENSE_RANK() OVER (ORDER BY salary DESC) AS rown
FROM
employee
)
SELECT
CASE
WHEN rown = 2 THEN salary
ELSE NULL
END AS SecondHighestSalary
FROM
cte;

sakshijain
ะะฒั‚ะพั€

The solutions are good sir but if there is a question where we have to find second highest salary from each departments then these solutions would not work I guess.

AbhishekKumar-ehed
visit shbcf.ru