Skip to content

Instantly share code, notes, and snippets.

@tphummel
Created May 28, 2013 18:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tphummel/5665020 to your computer and use it in GitHub Desktop.
Save tphummel/5665020 to your computer and use it in GitHub Desktop.
1)
select e.name from Employees e, Employees b where e.bossID = b.EmployeeID and e.Salary > b.Salary
2)
select * from (
select d.Name, e.Name, e.Salary, rank() over(partition by e.DepartmentID order by e.Salary DESC) as salRank from Departments d, Employees e where e.DepartmentID = d.DepartmentID) a where salRank = 1
3)
select * from (select departmentID , count(*) as ct from Employees group by departmentID) where ct < 3
4)
select max(d.Name), count(e.EmployeeID) as emps from Departments d left outer join Employees e on e.departmentID = d.departmentID group by d.DepartmentID
5)
select e.Name from Employees e, Employees b where e.BossID = b.EmployeeID and e.DepartmentID != b.DepartmentID
6)
select d.Name, sum(e.Salary) from Departments d, Employees e where e.DepartmentID = d.DepartmentID
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment