This discussion is archived
1 Reply Latest reply: Nov 14, 2013 10:16 PM by jariola RSS

Is these query Valid??

krishnagopi614 Newbie
Currently Being Moderated

51) Display the name of the employee who earns highest salary. I wrote like this "select last_name from employees  having max(salary)=salary" ; it gave an error like 'SQL Error: ORA-00937: not a single-group group function 00937. 00000 -  "not a single-group group function" Can anybody explain what the error is????????????????

  • 1. Re: Is these query Valid??
    jariola Guru
    Currently Being Moderated

    Hi,

     

    Unfortunately your query is not valid. You can try

     

    WITH qry AS (
      SELECT  last_name,
        salary,
        ROW_NUMBER() OVER(ORDER BY salary DESC) AS rn
    FROM employees
    )
    SELECT last_name,
      salary
    FROM qry
    WHERE rn =1
    
    

     

    Or

     

    WITH qry AS (
    SELECT  last_name,
      salary,
      max(salary) OVER() as max_sal
    FROM employees
    )
    SELECT last_name,
    salary
    FROM qry
    WHERE max_sal = salary
    

     

    Regards,

    Jari

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points