SELECT DISTINCT(A.SALARY) FROM EMPLOYEE A
WHERE &SALARY = (SELECT COUNT(DISTINCT(B.SALARY)) FROM EMPLOYEE B
WHERE A.SALARY<=B.SALARY);
&salary=nth number for nth highest salary.
MAX and SECOND MAX
NOTE : Select The second Highest
WHERE &SALARY = (SELECT COUNT(DISTINCT(B.SALARY)) FROM EMPLOYEE B
WHERE A.SALARY<=B.SALARY);
&salary=nth number for nth highest salary.
MAX and SECOND MAX
NOTE : Select The second Highest
SELECT MAX(salary) FROM employees WHERE salary < (SELECT MAX(salary) FROM employees)
NOTE :If there are ties then get the second highest as below :
Name Salary
Jim 6
Foo 5
Bar 5
Steve 4
SELECT name, salaryFROM employeesWHERE salary = (SELECT MAX(salary) FROM employees WHERE salary < (SELECT MAX(salary) FROM employees))
AVERAGE
SELECT
DepartmentID,
Avg(tblEmployeeInfo.Salary) AS DeptAvgSalary
FROM tblEmployeeInfo
GROUP BY DepartmentID;
No comments:
Post a Comment