Query employee information for each department minimum wage

Source: Internet
Author: User

Title:

Query employee information for each department minimum wage


Correlated subquery Methods


1 Query the minimum wage for each department

Select Deptno, Min (sal) min_sal from the EMP Group by DEPTNO;


2 Associated Personnel information with minimum wage

Select e.* from emp E, (select Deptno, min (sal) min_sal from EMP Group by deptno) Swhere E.deptno = S.deptnoand E.sal = S. Min_sal;


In keyword method


The In keyword is an easy way to think of this scenario by first querying the department's minimum wage and then matching the employee information for the minimum wage.


SELECT * from emp where Sal in (select min (sal) from EMP Group by DEPTNO);


Error parsing


In method, there is a problem when there are multiple identical wage values in both departments that produce incorrect results


Now, the user Department of EMPNO 1234 in EMP is modified to 20

Update emp Set deptno = where empno = 1234;

then use the In Query method to check departmental minimum wage employee information


At this time, empno for 1234 of the staff wages and Deptno 10 of the department minimum wage is the same, so use in query to find out the minimum wage.


But using a method query that Associates subqueries ,


In comparison, in a similar query, use the IN keyword to query directly, and to use the correlation sub-query step by step to check.



Query employee information for each department minimum wage

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.