0 evaluări0% au considerat acest document util (0 voturi)
11 vizualizări1 pagină
This document provides two SQL queries to find high salaries. The first query finds the second highest salary by selecting the maximum salary from employees where the salary is not the overall maximum. The second query finds the Nth highest salary by selecting employees where the count of distinct higher salaries is N-1.
This document provides two SQL queries to find high salaries. The first query finds the second highest salary by selecting the maximum salary from employees where the salary is not the overall maximum. The second query finds the Nth highest salary by selecting employees where the count of distinct higher salaries is N-1.
This document provides two SQL queries to find high salaries. The first query finds the second highest salary by selecting the maximum salary from employees where the salary is not the overall maximum. The second query finds the Nth highest salary by selecting employees where the count of distinct higher salaries is N-1.
WHERE Salary NOT IN (SELECT MAX(Salary) FROM Employee )
finding the nth highest salary in SQL
SELECT * /*This is the outer query part */ FROM Employee Emp1 WHERE (N-1) = ( /* Subquery starts here */ SELECT COUNT(DISTINCT(Emp2.Salary)) FROM Employee Emp2 WHERE Emp2.Salary > Emp1.Salary)