国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 數(shù)據(jù)庫 > Oracle > 正文

Oracle基礎(chǔ)學(xué)習(xí)之子查詢

2024-08-29 13:59:27
字體:
供稿:網(wǎng)友

首先使用子查詢的時候注意事項包括,子查詢可以嵌套多層和子查詢需要圓括號()括起來,下面我們來看看詳細(xì)的介紹。

基礎(chǔ)介紹

1,wherer:子查詢一般會返回單行單列 單行多列 多行單列 ;

2,having:子查詢會返回單行單列,同時表示要使用統(tǒng)計函數(shù);

3,from:子查詢返回多行多列數(shù)據(jù)(表結(jié)構(gòu));

4,select:返回單行單列 (一般不使用);

示例詳解

where(進(jìn)行數(shù)據(jù)行的篩選操作):

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:指的是與子查詢返回的內(nèi)容相同。

  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 :比子查詢的返回的最小值要小

     all :比子查詢的返回的最大值要大

     where子查詢的幾率很高;

having:

查詢出高于公司平均工資的職位名稱 職位人數(shù) 平均工資。

 select job,count(empno),avg(sal) from emp group by job  having avg(sal)>(select avg(sal) from emp);

select(一般不用):

查詢每個雇員的編號姓名 職位 部門名稱。

 select e.empno,e.ename,e.job, (select d.dname from dept d whered.deptno=e.deptno)from emp e;

(1+n) 次查詢;

from(重點(diǎn)):

查詢出每個部門的名稱 位置 部門人數(shù)。

 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(+);

多表查詢和子查詢都能實(shí)現(xiàn)統(tǒng)計,那么那種方式更好呢?

答:在實(shí)際的工作當(dāng)中,子查詢的主要目地是解決多表查詢的性能問題,所以在開發(fā)中使用的是 最多的。最大作用是解決多表查詢帶來的笛卡爾積影響性能的問題。

復(fù)雜查詢= 簡單查詢+限定查詢+ 多表查詢+ 分組統(tǒng)計查詢 +子查詢;

總結(jié)

以上就是關(guān)于Oracle子查詢的全部內(nèi)容,希望本文的內(nèi)容對大家學(xué)習(xí)或者使用Oracle能有所幫助,如果有疑問大家可以留言交流。


注:相關(guān)教程知識閱讀請移步到oracle教程頻道。
發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 惠州市| 林口县| 全南县| 汉川市| 邛崃市| 宁津县| 久治县| 上栗县| 宁德市| 昭通市| 米泉市| 台东市| 武川县| 西丰县| 北票市| 新和县| 焉耆| 东城区| 孟津县| 兴安县| 垦利县| 鄂尔多斯市| 阿尔山市| 海林市| 高要市| 抚宁县| 淮安市| 靖安县| 乐山市| 于都县| 紫金县| 九龙坡区| 江阴市| 平遥县| 奇台县| 唐河县| 赞皇县| 惠安县| 博白县| 两当县| 三都|