![數(shù)據(jù)庫(kù)技術(shù)與Oracle:sql-06 Subqueries_第1頁(yè)](http://file3.renrendoc.com/fileroot_temp3/2021-12/8/063f0f49-922c-48eb-b6db-3d6148ce9b2b/063f0f49-922c-48eb-b6db-3d6148ce9b2b1.gif)
![數(shù)據(jù)庫(kù)技術(shù)與Oracle:sql-06 Subqueries_第2頁(yè)](http://file3.renrendoc.com/fileroot_temp3/2021-12/8/063f0f49-922c-48eb-b6db-3d6148ce9b2b/063f0f49-922c-48eb-b6db-3d6148ce9b2b2.gif)
![數(shù)據(jù)庫(kù)技術(shù)與Oracle:sql-06 Subqueries_第3頁(yè)](http://file3.renrendoc.com/fileroot_temp3/2021-12/8/063f0f49-922c-48eb-b6db-3d6148ce9b2b/063f0f49-922c-48eb-b6db-3d6148ce9b2b3.gif)
![數(shù)據(jù)庫(kù)技術(shù)與Oracle:sql-06 Subqueries_第4頁(yè)](http://file3.renrendoc.com/fileroot_temp3/2021-12/8/063f0f49-922c-48eb-b6db-3d6148ce9b2b/063f0f49-922c-48eb-b6db-3d6148ce9b2b4.gif)
![數(shù)據(jù)庫(kù)技術(shù)與Oracle:sql-06 Subqueries_第5頁(yè)](http://file3.renrendoc.com/fileroot_temp3/2021-12/8/063f0f49-922c-48eb-b6db-3d6148ce9b2b/063f0f49-922c-48eb-b6db-3d6148ce9b2b5.gif)
版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
1、6Subqueries 6-2ObjectivesAfter completing this lesson, you should be able to do the following:Describe the types of problem that subqueries can solveDefine subqueriesList the types of subqueriesWrite single-row and multiple-row subqueries6-3Using a Subquery to Solve a ProblemWho has a salary greater
2、 than Abels?Which employees have salaries greater than Abels salary?Main Query:What is Abels salary?Subquery6-4Subquery SyntaxThe subquery (inner query) executes once before the main query.The result of the subquery is used by the main query (outer query).SELECTselect_listFROMtableWHEREexpr operator
3、 (SELECTselect_list FROMtable);6-5SELECT last_nameFROM employeesWHERE salary (SELECT salary FROM employees WHERE last_name = Abel);Using a Subquery110006-6Guidelines for Using SubqueriesEnclose subqueries in parentheses. Place subqueries on the right side of the comparison condition.The ORDER BY cla
4、use in the subquery is not needed unless you are performing top-n analysis.Use single-row operators with single-row subqueries and use multiple-row operators withmultiple-row subqueries.6-7Types of SubqueriesMain querySubqueryreturnsST_CLERK Multiple-row subqueryST_CLERKSA_MANMain querySubqueryretur
5、ns Single-row subquery6-8Single-Row SubqueriesReturn only one rowUse single-row comparison operatorsOperator= = =MeaningEqual toGreater than Greater than or equal to Less than Less than or equal toNot equal to6-9 SELECT last_name, job_id, salaryFROM employeesWHERE job_id = (SELECT job_id FROM employ
6、ees WHERE employee_id = 141)AND salary (SELECT salary FROM employees WHERE employee_id = 143);Executing Single-Row SubqueriesST_CLERK26006-10SELECT last_name, job_id, salaryFROM employeesWHERE salary = (SELECT MIN(salary) FROM employees);Using Group Functions in a Subquery25006-11The HAVING Clause w
7、ith SubqueriesThe Oracle server executes subqueries first.The Oracle server returns results into the HAVING clause of the main query.SELECT department_id, MIN(salary)FROM employeesGROUP BY department_idHAVING MIN(salary) (SELECT MIN(salary) FROM employees WHERE department_id = 50);25006-12SELECT emp
8、loyee_id, last_nameFROM employeesWHERE salary = (SELECT MIN(salary) FROM employees GROUP BY department_id);What Is Wrong With This Statement?ERROR at line 4:ORA-01427: single-row subquery returns more thanone rowSingle-row operator with multiple-row subquery6-13Will This Statement Return Rows?no row
9、s selectedSELECT last_name, job_idFROM employeesWHERE job_id = (SELECT job_id FROM employees WHERE last_name = No);Subquery returns no values6-14Multiple-Row SubqueriesReturn more than one rowUse multiple-row comparison operatorsOperator IN ANY ALLMeaningEqual to any member in the listCompare value
10、to each value returned by the subquery Compare value to every value returned by the subquery 6-15Using the ANY Operator in Multiple-Row Subqueries9000, 6000, 4200SELECT employee_id, last_name, job_id, salaryFROM employeesWHERE salary ANY (SELECT salary FROM employees WHERE job_id = IT_PROG)AND job_i
11、d IT_PROG;6-16SELECT employee_id, last_name, job_id, salaryFROM employeesWHERE salary ALL (SELECT salary FROM employees WHERE job_id = IT_PROG)AND job_id IT_PROG;Using the ALL Operator in Multiple-Row Subqueries9000, 6000, 4200 6-17Null Values in a SubquerySELECT emp.last_nameFROM employees empWHERE emp.employee_id NOT IN (SELECT mgr.manager_id FROM employees mgr);6-18SummaryIn this lesson, you should have learned how to:Ide
溫馨提示
- 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- Karrikinolide-3-ethyl-ester-生命科學(xué)試劑-MCE-7462
- Diammonium-phosphate-15N2-生命科學(xué)試劑-MCE-5147
- 1-3-Diheptadecanoyl-glycerol-生命科學(xué)試劑-MCE-9470
- 2025年度家居建材送貨司機(jī)合作協(xié)議書
- 二零二五年度綠色能源知識(shí)產(chǎn)權(quán)共享及資源利用合同
- 2025年度鋼筋加工企業(yè)節(jié)能減排合作協(xié)議
- 二零二五年度股權(quán)代持協(xié)議中的稅務(wù)影響與籌劃策略
- 2025年度藥店藥品質(zhì)量檢測(cè)員勞動(dòng)合同
- 2025年度養(yǎng)老產(chǎn)業(yè)股份轉(zhuǎn)讓協(xié)議書
- DB 3705T 50-2024設(shè)施蝴蝶蘭高效栽培技術(shù)規(guī)程
- 聚合物粘彈性
- 建筑工程施工現(xiàn)場(chǎng)安全資料管理規(guī)程解讀
- 養(yǎng)老護(hù)理員培訓(xùn)老年人日常生活照料
- 黑龍江省哈爾濱市八年級(jí)(下)期末化學(xué)試卷
- 各種抽油泵的結(jié)構(gòu)及工作原理幻燈片
- 學(xué)習(xí)弘揚(yáng)雷鋒精神主題班會(huì)PPT雷鋒精神我傳承爭(zhēng)當(dāng)時(shí)代好少年P(guān)PT課件(帶內(nèi)容)
- 社區(qū)獲得性肺炎的護(hù)理查房
- 體育賽事策劃與管理第八章體育賽事的利益相關(guān)者管理課件
- 專題7閱讀理解之文化藝術(shù)類-備戰(zhàn)205高考英語(yǔ)6年真題分項(xiàng)版精解精析原卷
- 《生物資源評(píng)估》剩余產(chǎn)量模型
- 2022年廣東省10月自考藝術(shù)概論00504試題及答案
評(píng)論
0/150
提交評(píng)論