When I reviewed the SQL statements for students, I had the following questions:
1. Find the average salary of everyone.
2. Find the average salary of each department.
3. Find the person with the highest salary.
4. Find the department with the highest average salary.
Some of you can do this quickly.AddedQuestion: Find out the information of the person whose salary is different from that of any other employee.
Answers provided by students:
Select * from employees E1 Where salary not in ( Select salary from employees E2 Where e1.employees _ ID! = E2.employees _ id )
Another reference answer:
Select * from employees
Where salary in
(
Select salary from
(
Select salary, count (salary) from employees
Group by salary
Having count (salary) = 1
)
)
The latter seems a little troublesome,However, in some cases (for example, when there are not many types of wages), the performance may be better.