Why cannot use 'having max()'?


  • 1
    N
    select Max(Salary) SecondHighestSalary
    from Employee
    where Salary<(select Salary from Employee having Max(Salary));
    

    I tried to use 'Max(Salary)' in 'having', but it showed wrong.

        select Max(Salary) SecondHighestSalary
        from Employee
        where Salary<(select Max(Salary) from Employee);
    

    And it can run correctly.

    Why cannot use 'having max()'?


  • 0
    F

    Having is used for aggregate function, your is a simple select - http://www.w3schools.com/sql/sql_having.asp


  • 0
    J

    This is wrong.
    If an attribute does not display after 'having' and it displays after 'select',it must use aggregate function.
    如果没有出现在having后面的属性出现在select中,那么其必须使用聚合函数。


Log in to reply
 

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