Wednesday, August 15, 2012

department wise max salary in sql

Department wise Max salaries:


SELECT
  Employee.*
FROM
  (select
  deptno, max(salary) as MaxSalary
from
  Employee
group by
  DeptNo) MaxSalaries
INNER JOIN
  Employee
ON
  Employee.DeptNo = MaxSalaries.DeptNo AND
  Employee.Salary  = MaxSalaries.MaxSalary

 Top 2 salaries


SELECT
top 2  Employee.*
FROM
  (select
  deptno, max(salary) as MaxSalary
from
  Employee
group by
  DeptNo) MaxSalaries
INNER JOIN
  Employee
ON
  Employee.DeptNo = MaxSalaries.DeptNo AND
  Employee.Salary  = MaxSalaries.MaxSalary

2 nd height salary

SELECT MAX(SALARY) FROM EMPLOYEE WHERE SALARY NOT IN (SELECT MAX(SALARY) FROM EMPLOYEE)

No comments:

Post a Comment