LeetCode 177: Nth Highest Salary [SQL]

Поделиться
HTML-код
  • Опубликовано: 11 дек 2024

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

  • @frederikmuller
    @frederikmuller  2 года назад

    If you want to have access to more free SQL problems, check out StrataScratch: stratascratch.com/?via=frederik

  • @mrprime557
    @mrprime557 2 года назад +1

    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 года назад +1

      sometimes you just gotta be honest and not let pride get in the way :)

  • @cathymccarthy4585
    @cathymccarthy4585 Год назад

    Straight to the point, considers edge cases. Thanks for the helpful video!

  • @mindyng1124
    @mindyng1124 3 года назад +2

    clear, thorough and quick to digest especially at 1.25 speed :D keep up the very helpful and excellent content! thx Frederik

  • @lakshmim1759
    @lakshmim1759 3 года назад +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

  • @mohammadghazanfar7228
    @mohammadghazanfar7228 3 года назад +7

    What about the NULL part? What if the Nth place has no salary, NULL - that wasn't taken in cosnideration?

  • @hsrboys9993
    @hsrboys9993 3 года назад

    Love your videos - much love from Berkeley!

  • @yajurnigam2567
    @yajurnigam2567 2 года назад +1

    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

  • @mickyman753
    @mickyman753 2 года назад

    do we need to learn these function things too ?

  • @sachin-b8c4m
    @sachin-b8c4m 5 месяцев назад

    very helpful

  • @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?

  • @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

  • @the_fat_journal
    @the_fat_journal 4 года назад +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  4 года назад +1

      Thank you for contributing your solution!

    • @hamzaehsankhan
      @hamzaehsankhan 3 года назад

      Could you please explain your solution as well?

  • @sundaytalks1390
    @sundaytalks1390 3 года назад +1

    Thank you sir!

  • @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;

  • @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 года назад +1

      maybe you need to change the SQL dialect. I’m using MySQL.

  • @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 года назад +1

      I think there are some words missing from the question.

  • @reddytintaya6749
    @reddytintaya6749 2 года назад

    I was crazy, why this was not working ... I forgot the ; :| 😆