oracle--子查詢--bai

來源:互聯網
上載者:User

標籤:highlight   view   div   from   group by   rom   csharp   com   show   

-- 1 建立視圖 show_max_sal_name_view 顯示工資最高的員工姓名及他的工資 create or replace view show_max_sal_name_view asselect ename,sal from scott.emp where sal=(select max(sal) from scott.emp);select * from show_max_sal_name_view;--2 建立視圖 show_min_sal_dname 顯示平均工資最低的部門的部門名及平均工資    --先按部門統計平均工資    select deptno,avg(sal) from scott.emp group by deptno;    --獲得最低的平均工資    select min(avg(sal))from scott.emp group by deptno;    --獲得最低平均工資及其部門號    select * from    (select deptno,avg(sal) 平均工資 from scott.emp  group by deptno) t    where t.平均工資 =     (select min(avg(sal)) from scott.emp group by deptno);    --獲得最低平均工資及其部門名  建立視圖    create or replace view show_min_sal_dname as    select * from    (select deptno,avg(sal) 平均工資 from scott.emp  group by deptno) t    where t.平均工資 =     (select min(avg(sal)) from scott.emp group by deptno);    --3 建立視圖 show_leader_name 顯示所有員工的名字和他們上級領導名。 (難)     --使用mgr欄位進行emp表的“自關聯”     select e1.ename as 員工名字,e2.ename as 領導名字 from scott.emp e1,scott.emp e2     where e1.mgr=e2.empno      union     select ename,‘無領導‘from scott.emp where mgr is null;=========================================================================================================-- 把空替換成0  update scott.emp set comm = ‘0‘ where comm is null;  --查出下級比上級 工資+獎金 高的員工編號,員工姓名  create view show_higher_empee as   select * from(  select e1.empno,e1.ename as 本人姓名,e2.ename as 領導姓名,e1.sal+nvl(e1.comm,‘0‘) as 本人總收入,  e2.sal+nvl(e2.comm,‘0‘) as 領導總收入    from scott.emp e1,scott.emp e2 where e1.mgr=e2.empno    ) where 本人總收入>領導總收入;        --採用join串連            select * from      (      select e1.empno,e1.ename as 本人姓名,e2.ename as 領導姓名,      e1.sal+nvl(e1.comm,‘0‘) as 本人總收入,      e2.sal+nvl(e2.comm,‘0‘) as 領導總收入      from scott.emp e1 inner join scott.emp e2 on e1.mgr=e2.empno      )      where 本人總收入>領導總收入;          select * from show_higher_empee;

  

oracle--子查詢--bai

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.