oracle--Sub-query--bai

Source: Internet
Author: User

--1 CREATE VIEW Show_max_sal_name_view display the highest wage employee name and his salary create or replace view Show_max_sal_name_view asselect Ename,sal from SC Ott.emp where sal= (select Max (sal) from scott.emp), select * from show_max_sal_name_view;--2 CREATE VIEW Show_min_sal_dname show average work    The department name and average wage of the lowest-funded sector-the average wage by sector select DEPTNO,AVG (SAL) from the Scott.emp group by Deptno;    --Get the lowest average wage select min (avg (SAL)) from the Scott.emp group by Deptno;     --Get the minimum average wage and its department number select * FROM (select Deptno,avg (SAL) Average salary from Scott.emp Group by deptno) T where T. Average salary =    (Select min (avg (SAL)) from Scott.emp Group by Deptno); --Get the minimum average wage and its department name create a view created or replace view show_min_sal_dname as SELECT * FROM (select Deptno,avg (sal) Average salary fro    M scott.emp GROUP by deptno) T where T. Average salary = (select min (sal)) from Scott.emp Group by Deptno); --3 Create a View show_leader_name displays the names of all employees and their superior leader names. (difficult)--using the MGR field for the "self-correlating" select E1.ename as employee name of the EMP table, E2.ename as leader name from Scott.emp e1,scott.emp E2 where e1.mgr    =e2.empno  Union select Ename, ' no leader ' from Scott.emp where Mgr is null;===========================================================  ==============================================--replace empty with 0 update scott.emp Set comm = ' 0 ' where comm is null; --Identification of employee numbers lower than higher salary + bonus, employee name CREATE VIEW Show_higher_empee as SELECT * FROM (select E1.empno,e1.ename as name, E2.ename As leader's name, E1.SAL+NVL (E1.comm, ' 0 ') as my total income, E2.SAL+NVL (E2.comm, ' 0 ') as leader revenue from Scott.emp e1,scott.emp E2 where e1.mgr        =e2.empno) where I own total revenue > lead revenue; --Using Join connection SELECT * FROM (select E1.empno,e1.ename as my name, E2.ename as leader name, E1.SAL+NVL (e1.comm      , ' 0 ') as my total revenue, E2.SAL+NVL (E2.comm, ' 0 ') as leader revenue from Scott.emp E1 INNER join scott.emp E2 on E1.mgr=e2.empno          Where I own total revenue > lead revenue; SELECT * from Show_higher_empee;

  

oracle--Sub-query--bai

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.