当前位置:网站首页>MySQL Niuke brush questions

MySQL Niuke brush questions

2022-06-23 07:14:00 Begin to change

Catalog

One 、 Get all non manager Employee salary , give dept_no、emp_no as well as salary

1、 subject  

2、 Ideas

3、 Source code


One 、 Get all non manager Employee salary , give dept_no、emp_no as well as salary

        1、 subject  

             

 

2、 Ideas

         First, combine the employee information and salary into a table , The same is true of managers ;

         Then connect the two tables , The connection condition is that the department number is the same , Finally, find the desired information from this large table , The precondition is that the employee's salary is greater than the manager's salary ;

        The manager is also part of the staff , So the data in the first table contains the manager's data , But this doesn't affect the later results , Because what is needed is that the salary is greater than, it is excluded

        If the condition is greater than or equal to , It is necessary to judge whether the employee number is in the manager table before establishing the employee salary table ;

3、 Source code

select b1.emp_no, manager_no, emp_salary, manager_salary
from(
    select dept_no, de.emp_no, salary as emp_salary
    from dept_emp as de
    join salaries as s
    on de.emp_no = s.emp_no
    )as b1
join (
    select dept_no, dm.emp_no as manager_no, salary as manager_salary
    from dept_manager as dm
    join salaries as s
    on dm.emp_no = s.emp_no
    )as b2
on b1.dept_no = b2.dept_no
where b1.emp_salary > b2.manager_salary

原网站

版权声明
本文为[Begin to change]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/174/202206230623599434.html