Skip to content

Instantly share code, notes, and snippets.

@lyleaf
Last active November 19, 2015 16:40
Show Gist options
  • Save lyleaf/e6345384ecb73dc8f8c9 to your computer and use it in GitHub Desktop.
Save lyleaf/e6345384ecb73dc8f8c9 to your computer and use it in GitHub Desktop.
--求一列中第二大的数据
select max(PersonId) from Address where PersonID not in (select MAX(PersonId) FROM Address)
--Use < is faster than not in
SELECT max(Salary)
FROM Employee
WHERE Salary <
(SELECT max(Salary)
FROM Employee);
--找出最个部门的工资收入最高的3个人
Select dep.Name as Department, emp.Name as Employee, emp.Salary from Department dep,
Employee emp where emp.DepartmentId=dep.Id and
(Select count(distinct Salary) From Employee where DepartmentId=dep.Id and Salary>emp.Salary)<3
--No more than 2 higher salary can be found in the departement.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment