程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 數據庫知識 >> Oracle數據庫 >> Oracle數據庫基礎 >> Oracle操作常見的代碼分析

Oracle操作常見的代碼分析

編輯:Oracle數據庫基礎

求部門中哪些人的薪水最高

以下是代碼片段:select ename,sal from emp join (select max(sal) max_sal, deptno from emp group by deptno) t on (emp.sal = t.max_sal and emp.deptno = t.deptno); -

求部門平均薪水的等級

以下是代碼片段:select deptno,avg_sal,grade from (select deptno,avg(sal) avg_sal from emp group by deptno) t join salgrade s on (t.avg_sal between s.losal and s.hisal);

求部門平均的薪水等級

以下是代碼片段:select deptno,avg(grade) from (select deptno,ename,grade from emp join salgrade s on (emp.sal between s.losal and s.hisal)) t group by deptno;

雇員中哪些人是經理人

以下是代碼片段:select ename from emp where empno in (select distinct mgr from emp);

不用組函數,求薪水的最高值

以下是代碼片段:select sal from emp where sal not in (select distinct e1.sal from emp e1 join emp e2 on (e1.sal < e2.sal))

用組函數,求薪水的最高值

以下是代碼片段:
select max(sal) from emp;

求平均薪水最高的部門的部門編號

以下是代碼片段:select deptno , avg_sal from (select avg(sal) avg_sal,deptno from emp group by deptno) t where avg_sal = (select max(avg_sal) from (select avg(sal) avg_sal,deptno from emp group by deptno) t);

組函數嵌套的寫法

以下是代碼片段:select deptno , avg_sal from (select avg(sal) avg_sal,deptno from emp group by deptno) t where avg_sal = (select max(avg(sal)) from emp group by deptno);

求平均薪水最高的部門的名稱

以下是代碼片段:select dname from dept where deptno = ( select deptno from (select avg(sal) avg_sal,deptno from emp group by deptno) t where avg_sal = (select max(avg_sal) from (select avg(sal) avg_sal,deptno from emp group by deptno) t) );

求平均薪水的等級最低的部門的部門名稱

以下是代碼片段:select avg(sal) avg_sal,deptno from emp group by deptno

部門平均薪水

以下是代碼片段:select min(avg_sal) from ( select avg(sal) avg_sal,deptno from emp group by deptno )

平均工資的最小值

以下是代碼片段:select avg_sal,deptno from (select avg(sal) avg_sal,deptno from emp group by deptno) t where avg_sal = ( select min(avg_sal) from ( select avg(sal) avg_sal,deptno from emp group by deptno ) )

平均工資的最小值及部門編號

以下是代碼片段:select t.avg_sal,t.deptno,s.grade from (select avg(sal) avg_sal,deptno from emp group by deptno) t join salgrade s on (t.avg_sal between s.losal and s.hisal) where avg_sal = ( select min(avg_sal) from ( select avg(sal) avg_sal,deptno from emp group by deptno ) )

平均工資的最小值及部門編號和工資等級

以下是代碼片段:select d.dname,t.avg_sal,t.deptno,s.grade from (select avg(sal) avg_sal,deptno from emp group by deptno) t join salgrade s on (t.avg_sal between s.losal and s.hisal) join dept d on (t.deptno = d.deptno) where avg_sal = ( select min(avg_sal) from ( select avg(sal) avg_sal,deptno from emp group by deptno ) )

平均工資的最小值及部門編號和工資等級及部門名稱

Another 按照題意的寫法

以下是代碼片段:select t1.deptno,t1.avg_sal,grade,d.dname from ( select deptno,avg_sal,grade from (select deptno,avg(sal) avg_sal from emp group by deptno) t join salgrade s on (t.avg_sal between s.losal and s.hisal) ) t1 join dept d on (t1.deptno = d.deptno) where grade = ( select min(grade) from ( select deptno,avg_sal,grade from (select deptno,avg(sal) avg_sal from emp group by deptno) t join salgrade s on (t.avg_sal between s.losal and s.hisal) ) );

創建視圖或者表,如果沒有權限

以下是代碼片段:conn sys/sys as sysdba;

已連接。

以下是代碼片段:grant create table, create vIEw to scott;

本文就為大家介紹這麼多,這只是其中的一小部分,還有很多這裡沒有介紹到,以後還會繼續為大家介紹更多的知識,希望能夠幫助到大家。

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved