LeetCode 177: Nth Highest Salary [SQL]

  Рет қаралды 23,398

Frederik Müller

Frederik Müller

Күн бұрын

Solution and walkthrough of leetcode database problem 177: Nth Highest Salary. I'm using MySQL but this solution should work in any SQL dialect such as PostgreSQL SQL Server, etc.
Link to the problem: leetcode.com/p...
Check out my StrataScratch videos: • StrataScratch Coding Q...

Пікірлер: 24
@frederikmuller
@frederikmuller 2 жыл бұрын
If you want to have access to more free SQL problems, check out StrataScratch: stratascratch.com/?via=frederik
@mrprime557
@mrprime557 2 жыл бұрын
Love the way you explain. I have been making the same mistakes. Instead of going to the answer directly, youve mentioned your mistakes and guided to answer :)
@frederikmuller
@frederikmuller 2 жыл бұрын
sometimes you just gotta be honest and not let pride get in the way :)
@mohammadghazanfar7228
@mohammadghazanfar7228 2 жыл бұрын
What about the NULL part? What if the Nth place has no salary, NULL - that wasn't taken in cosnideration?
@mindyng1124
@mindyng1124 3 жыл бұрын
clear, thorough and quick to digest especially at 1.25 speed :D keep up the very helpful and excellent content! thx Frederik
@cathymccarthy4585
@cathymccarthy4585 10 ай бұрын
Straight to the point, considers edge cases. Thanks for the helpful video!
@lakshmim1759
@lakshmim1759 3 жыл бұрын
MS SQLServer : select nullif(salary,null) from (select DISTINCT Salary from (select Salary, DENSE_RANK() OVER(ORDER BY Salary DESC) as d_rank from Employee) as sub where d_rank = @N )as salary
@hsrboys9993
@hsrboys9993 3 жыл бұрын
Love your videos - much love from Berkeley!
@viru_viral
@viru_viral Жыл бұрын
When I try to run the code with the solution you described in the video, It fails with "Runtime Error" message. Submitting the same code accepted though, did not find a clear explanation in leetcode discussion as well. Can you let me know why that might be happening?
@user-zf3it3vw2e
@user-zf3it3vw2e 2 ай бұрын
very helpful
@vaibhavpatharkar6794
@vaibhavpatharkar6794 Жыл бұрын
Very nice bro. But is it mysql or postgre becz i never studied SET operation and Function in sql. Pl help here. Pl give explanation for this
@sundaytalks1390
@sundaytalks1390 3 жыл бұрын
Thank you sir!
@the_fat_journal
@the_fat_journal 3 жыл бұрын
This is good but won't work in SQL Server, we don't have anything like offset there. this is how I wrote it for SQL Server: "select distinct e1.salary from employee e1 where (@N-1) = (select count(distinct salary) from employee e2 where e2.salary > e1.salary)"
@frederikmuller
@frederikmuller 3 жыл бұрын
Thank you for contributing your solution!
@hamzaehsankhan
@hamzaehsankhan 3 жыл бұрын
Could you please explain your solution as well?
@mickyman753
@mickyman753 2 жыл бұрын
do we need to learn these function things too ?
@yajurnigam2567
@yajurnigam2567 2 жыл бұрын
SQL SERVER CREATE FUNCTION getNthHighestSalary(@N INT) RETURNS INT AS BEGIN RETURN ( Select distinct salary from (Select salary ,Dense_Rank() over(order by salary desc) DENSERANK from Employee) as q where DENSERANK=@N ); END
@anushreepatil4811
@anushreepatil4811 3 жыл бұрын
Question : List the riders_id who started their journey yesterday in Delhi and completed their last journey in Noida that too yesterday. Columns were: riders_id, drivers_id, city_from,city_to,pickup_time(timestamp),drop_off_time(timestamp) I was asked this question in one of my uber interviews. Could you please solve it for me?
@frederikmuller
@frederikmuller 3 жыл бұрын
I think there are some words missing from the question.
@stockjanitor
@stockjanitor 2 жыл бұрын
hello, i been watching your video, it is helpful and clear, but when submit to leetcode, the codes wont work,
@frederikmuller
@frederikmuller 2 жыл бұрын
maybe you need to change the SQL dialect. I’m using MySQL.
@mritunzaysingh8978
@mritunzaysingh8978 2 жыл бұрын
can anyone tell me that my query in a right way or not select salary FROM ( select id,salary,rank() over(order by salary desc) as rnk from person ) A where A.rnk = 2;
@mritunzaysingh8978
@mritunzaysingh8978 2 жыл бұрын
or select salary FROM ( select id,salary,dense_rank() over(order by salary desc) as rnk from person ) A where A.rnk = 2;
@reddytintaya6749
@reddytintaya6749 Жыл бұрын
I was crazy, why this was not working ... I forgot the ; :| 😆
LeetCode 178: Rank Scores [SQL]
7:13
Frederik Müller
Рет қаралды 15 М.
Very Famous SQL Interview Question | Department Highest Salary
13:39
Секрет фокусника! #shorts
00:15
Роман Magic
Рет қаралды 81 МЛН
Leetcode SQL Interview Questions  | Practise SQL questions
17:50
Sumit Mittal
Рет қаралды 21 М.
Leetcode 177 - Nth Highest Salary - Python Solution | FAANG Interviews
8:06
Everyday Data Science
Рет қаралды 1 М.
LeetCode Medium 176 Amazon Interview SQL Question with Detailed Explanation
9:44
Everyday Data Science
Рет қаралды 4,1 М.
LeetCode 185: Department Top Three Salaries [SQL]
9:33
Frederik Müller
Рет қаралды 14 М.
Why you should not be a data scientist
12:33
Tina Huang
Рет қаралды 761 М.
LeetCode 176: Second Highest Salary [SQL]
7:19
Frederik Müller
Рет қаралды 19 М.
Three Tricky Analytics Interview Questions with Andrew
25:03
Jay Feng
Рет қаралды 80 М.