A question for students: Find employees whose salaries are different from any other employee

Source: Internet
Author: User

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.

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.