Why does this not work ? ( by using limit )


  • 0
    N
    SELECT 
      IF(SUM< 1, NULL, s) AS salary 
    FROM
      (SELECT 
        salary AS s,
        COUNT(salary) AS SUM
      FROM
        Employee 
      ORDER BY salary DESC 
      LIMIT 1, 1) sub

  • 0
    L

    Your inner query has aggregate function COUNT, so only one row of each group (if has GROUP BY) will be returned and of course no second row.
    I think your inner query should be something like

    SELECT DISTINCT
        Salary
    FROM
        Employee
    ORDER BY Salary DESC
    LIMIT 1 , 1

  • 0
    N

    because the inner query should contain the num of each salary occurrence , so that I can decide if the select clause should return null or not . above all ,thank you ! I added the group by ,then it works !


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.