標籤: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