首先使用子查詢的時候注意事項包括,子查詢可以嵌套多層和子查詢需要圓括號()括起來,下面我們來看看詳細的介紹。
基礎介紹
1,wherer:子查詢一般會傳回單行單行多列多行單列;
2,having:子查詢會傳回單行單列,同時表示要使用統計函數;
3,from:子查詢傳回多行多列資料(表格結構);
4,select:傳回單行單列(一般不使用);
範例詳解
where(進行資料行的篩選運算):
a:查詢出出低於公司平均薪資的員工資料。
select * from emp where sal<(select avg(sal) from emp);
以上的查詢返回單行單列可以作為where子句的過濾條件使用;
b:查詢公司最早僱用的僱員的資訊。
select * from emp where hiredate= (select MIN(hiredate) from emp);
C:查詢與scott從事同一工作且薪資相同的員工資訊。
select* from emp where (job,sal) =( select job,sal from emp where ename ='scott') and ename <>'scott';
in:指的是與子查詢回傳的內容相同。
select * from emp where sal in (select sal from emp where job = 'manager');
not in:
select* from emp where sal not in(select sal from emp where job='manager');
子查詢中不能有空。
any:
select* from emp where sal = any(select sal from emp where job='manager'); select* from emp where sal > any(select sal from emp where job='manager');
比子查詢的返回的最大值要大
select* from emp where sal < any(select sal from emp where job='manager');
比子查詢返回的最大值要小
all:
all :比子查詢的回報的最大值大 where子查詢的幾率很高; having: 查詢出高於公司平均工資的職位名稱職位人數平均工資。 select(一般不用): 查詢每位員工的編號姓名 職位 部門名稱。 (1+n) 次查詢; from(重點): 查詢出每個部門的名稱 位置 部門人數。 (多表查詢) 多表查詢和子查詢都能實現統計,那麼那種方式更好呢? 答:在實際的工作當中,子查詢的主要目地是解決多表查詢的效能問題,所以在開發中使用的是 最多的。最大作用是解決多表查詢所帶來的笛卡爾積影響效能的問題。 複雜查詢= 簡單查詢+限定查詢+ 多表格查詢+ 分組統計查詢+子查詢; 總結 以上就是關於Oracle子查詢的全部內容,希望本文的內容對大家學習或使用Oracle能有所幫助,如果有疑問大家可以留言交流。 更多Oracle基礎學習之子查詢相關文章請關注PHP中文網! select job,count(empno),avg(sal) from emp group by job
having avg(sal)>(select avg(sal) from emp);
select e.empno,e.ename,e.job,
(select d.dname from dept d whered.deptno=e.deptno)from emp e;
select d.dname,d.loc,count(e.empno)
from emp e,dept d
where e.deptno(+)=d.deptno
group by d.dname,d.loc;
分步1: select d.deptno,d.dname,d.locfrom dept d;
分步2:select deptno,count(empno)from emp group by deptno;
正确的查询:
select d.deptno,d.dname,d.loc,temp.count
from dept d,(select deptno,count(empno) count from emp
group by deptno) temp
where d.deptno=temp.deptno(+);

熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

AI Hentai Generator
免費產生 AI 無盡。

熱門文章

熱工具

Safe Exam Browser
Safe Exam Browser是一個安全的瀏覽器環境,安全地進行線上考試。該軟體將任何電腦變成一個安全的工作站。它控制對任何實用工具的訪問,並防止學生使用未經授權的資源。

記事本++7.3.1
好用且免費的程式碼編輯器

Dreamweaver CS6
視覺化網頁開發工具

MinGW - Minimalist GNU for Windows
這個專案正在遷移到osdn.net/projects/mingw的過程中,你可以繼續在那裡關注我們。 MinGW:GNU編譯器集合(GCC)的本機Windows移植版本,可自由分發的導入函式庫和用於建置本機Windows應用程式的頭檔;包括對MSVC執行時間的擴展,以支援C99功能。 MinGW的所有軟體都可以在64位元Windows平台上運作。

PhpStorm Mac 版本
最新(2018.2.1 )專業的PHP整合開發工具