The employee's name, salary, Department name, salary level in the company and the name of the leader, the salary of the leader, and the level corresponding to the leader are displayed.

Source: Internet
Author: User
Tags dname

The employee's name, salary, Department name, salary level in the company and the name of the leader, the salary of the leader, and the level corresponding to the leader are displayed.

Example:

The employee's name, salary, Department name, salary level in the company and the name of the leader, the salary of the leader, and the level corresponding to the leader are displayed.

This is a thinking question between emp, dept, and salgrade tables under oracle's default Scott user.

Analysis: first, identify the content in the salary level table (salgrade ).

select * from salgrade;

Query the name, salary, Department name, and salary of each employee in the company's salgrade)

SELECT distinct e.ename,e.sal,d.dname,g.grade e_grade FROM emp e,dept d,salgrade g,emp sWHERE (e.deptno=d.deptno) AND (e.sal BETWEEN g.losal AND g.hisal);

Add the name of the Supervisor

SELECT e.ename,e.sal,d.dname,g.grade,s.ename FROM emp e,dept d,salgrade g,emp s WHERE (e.deptno=d.deptno) AND (e.sal BETWEEN losal AND hisal) AND (s.empno=e.mgr);

Finally, determine the employee's manager name, the manager's salary, and the level corresponding to the manager's salary.

SELECT e.ename,e.sal,d.dname,g.grade e_grade,s.ename mgr_name,g2.grade m_gradeFROM emp e,dept d,salgrade g,emp s,salgrade g2WHERE (e.deptno=d.deptno) AND (e.sal BETWEEN g.losal AND g.hisal) AND (s.empno=e.mgr) AND (s.sal BETWEEN g2.losal AND g2.hisal);

Authorization + bH87XDtcS94bn7sLTI59H5yr3P1Mq + accept/accept + accept/K/cc0yrxp11_vcd4kpha + PHByZSBjbGFzcz0 = "brush: SQL;"> SELECT e. ename, e. sal, d. dname, decode (g. grade, 5, 'first-level wage ', 4, 'second-level wage', 3, 'third-level wage ', 2, 'Fourth-level wage', 1, 'Wait 5') e_grade, s. ename mgr_name, s. sal mgr_sal, decode (g2.grade, 5, 'First wage ', 4, 'second wage', 3, 'third wage ', 2, 'Fourth wage ', 1, 'fifth-level wage ') m_gradeFROM emp e, dept d, salgrade g, emp s, salgrade g2WHERE (e. deptno = d. deptno) AND (e. sal BETWEEN g. losal AND g. hisal) AND (s. empno = e. mgr) AND (s. sal BETWEEN g2.losal AND g2.hisal)



Related Article

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.