oracle中的with的用法,oracle中with子句的用法(轉)

語法:

WITH query_name AS (subquery)

[, query_name AS (subquery) ]...

使用在主select關鍵字前,oracle將其當做一個內聯視圖或者臨時表使用。

例子:

1.最簡單的使用方法:

如查詢部門名稱包含“A”的所有員工信息

--with clause

with a as

(select deptno from dept where dname like '%A%')

select * from emp where deptno in (select * from a);

with a as

(select deptno from dept where dname like '%A%'),--a結果集

a2 as(select * from a where deptno>20)--a1結果集直接從a中篩選

select * from emp where deptno in (select * from a2);

2.多層同級只能用一個with,并且后面的結果集可以使用前面的結果集:

查詢部門名稱包含“A”并且部門編號大于20的所有員工信息

with a as

(select deptno from dept where dname like '%A%'),--a結果集

a2 as(select * from a where deptno>20)--a1結果集直接從a中篩選

select * from emp where deptno in (select * from a2);

3.不同級查詢可以使用多個with:

查詢部門名稱包含“A”并且部門編號大于20的所有員工信息的另外一種實現方式如下

with a as

(select deptno from dept where dname like '%A%')--a結果集

select * from emp where deptno in (--括號內層作為子查詢,為第二級

with a2 as(select * from a where deptno>20)--a1結果集直接從a中篩選

select * from a2

);

使用場景:

那什么情況下能使用到with子句呢?以下我就舉幾個簡單的例子,簡單的說明以下:

1.我想測試一句sql,而我不想專門建立一個測試表:

我想測試成績大于90的學生,我不想建立學生表,可以用到with子句

with stu as(

select '張娜' sname,99 score from dual union

select '王杰' ,35 from dual union

select '宋麗' ,85 from dual union

select '陳曉' ,73 from dual union

select '李元' ,100 from dual

)--with 組成一個臨時的結果集,存放在用戶的臨時表空間

select * from stu where score>90

2.???????? 當一個sql重復用到某個相同的結果集作為子查詢:

--查詢銷售部工資>1500或者銷售部工資小于1000的員工

select * from emp where deptno=(select deptno from dept where dname ='SALES') and sal >1500

union all

select * from emp where deptno=(select deptno from dept where dname ='SALES') and sal <1000

--以上sql select deptno from dept where dname ='SALES'需要執行兩次,影響效率

--可以使用with優化一下

with salno as(select deptno from dept where dname ='SALES')

select * from emp where deptno=(select * from salno) and sal >1500

union all

select * from emp where deptno=(select * from salno) and sal <1000

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/378470.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/378470.shtml
英文地址,請注明出處:http://en.pswp.cn/news/378470.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

模擬一個排隊系統

現在有一個數據源&#xff0c;有兩種狀態&#xff08;ON OFF&#xff09;&#xff0c;ON的持續時間服從均值為T_on的指數分布&#xff0c;OFF的持續時間服從均值為T_off的指數分布&#xff0c;源只在ON的時候產生數據包&#xff0c;服從均值為λ的指數分布 模擬一個排隊系統 每…

stl中copy()函數_std :: copy_if()函數以及C ++ STL中的示例

stl中copy()函數C STL std :: copy_if()函數 (C STL std::copy_if() function) copy_if() function is a library function of algorithm header, it is used to copy the elements of a container, it copies the certain elements (which satisfy the given condition) of a…

C++語法:求vector中的最大值及其位置

代碼&#xff1a; #include <iostream> #include <vector> #include <algorithm> using namespace std;int main(){vector<int> a { 2,4,6,7,1,0,8,9,6,3,2 };auto maxPosition max_element(a.begin(), a.end());cout << *maxPosition <&l…

二、織物具備超級防水效果的條件?

織物具備超級防水效果的條件? 收集資料階段 蓮花效應(Lotus Effect),指蓮葉表面具有超疏水(superhydrophobicity)以及自潔(self-cleaning)的特性。 由于蓮葉具有疏水、不吸水的表面,落在葉面上的雨水會因表面張力的作用形成水珠,換言之,水與葉面的接觸角(contacta…

C#編碼簡單性之函數篇(如何編寫簡短的C#代碼,隨時更新)

作者&#xff1a;陳勇出處&#xff1a;blog.csdn.net/cheny_com這是編碼簡單性系列中的其中一篇&#xff0c;之前幾篇包括代碼篇和語義篇。因為要積累案例&#xff0c;會隨時更新。之前提到&#xff1a;編碼簡單性的“心法”就是&#xff1a;只要屏幕上有任何兩部分代碼看上去相…

R學習筆記(1):R是什么

本文最新版已更新至http://thinkinside.tk/2013/05/03/r_notes_1_what.html 在學習量化投資的時候&#xff0c;我發現了R&#xff08;www.r-project.org&#xff09;。R到底是什么呢&#xff1f;在開始之前&#xff0c;先看看R的神奇之處。 1. R初窺 從CRAN&#xff08;The Co…

oracle網卡,Oracle_bond網卡配置

***************************loyu*******************************************************雙網卡創建bond虛擬網卡實驗*************************cat > /etc/sysconfig/network-scripts/ifcfg-bond0 << EofDEVICEbond0BOOTPROTOstaticONBOOTyesIPADDR172.16.116.60N…

Python | 展示一個break語句示例

break is a keyword in python just like another programming language and it is used to break the execution of loop statement. 就像另一種編程語言一樣&#xff0c; break是python中的關鍵字&#xff0c;用于中斷loop語句的執行。 In the given example, loop is runni…

數字圖像處理知識總結

一&#xff1a;基本概念 數字圖像&#xff1a;指由被稱作像素的小塊區域組成的二維矩陣。將物理圖像行列劃分后&#xff0c;每個小塊區域稱為像素&#xff08;pixel&#xff09;。每個像素包括兩個屬性&#xff1a;位置和灰度。圖像數字化一般分為采樣、量化與編碼三個步驟。數…

三、“滌綸纖維和棉纖維兩組分纖維在滌/棉混紡織物燃燒過程中有著明顯的物理相互作用和化學相互作用”,解釋這兩種作用。

“滌綸纖維和棉纖維兩組分纖維在滌/棉混紡織物燃燒過程中有著明顯的物理相互作用和化學相互作用”,解釋這兩種作用。 收集資料階段 棉纖維燃燒后炭化,而滌綸燃燒時熔融滴落,由于棉纖維成為支持體,可使熔融纖維聚集,并阻止其滴落,使熔融纖維燃燒更加劇烈,即所謂"支架效應…

關于性能測試的通俗解釋

關于性能測試的通俗解釋: http://www.docin.com/p-645879730.html 轉載于:https://www.cnblogs.com/preftest/archive/2013/05/03/3057231.html

oracle marley,滾石雜志500大專輯,對歐美音樂感興趣的可以找來聽聽。

滾石雜志于2003年11月評選出的滾石雜志五百大專輯。值得一提的是&#xff0c;披頭士樂隊占據了前五中的三席&#xff0c;前五十中的7席&#xff0c;正式出版的專輯幾乎全部入選前五百。排名 演唱者 專輯001 披頭士樂隊(The Beatles) Sgt. Peppers Lonely Hearts Club Band002 海…

ci中使用smarty

<p>d</p> <?php defined(BASEPATH) or die(Access restricted!);/** 作者&#xff1a;晉勇*/require(APPPATH.libraries/smarty/Smarty.class.php);classCismarty extendsSmarty{public$exttpl;public$dir;public$layoutlayout/main;/** * 構造函數 * * access…

kinect中psi是什么_PSI的完整形式是什么?

kinect中psi是什么PSI&#xff1a;每平方英寸磅/國際人口服務 (PSI: Pound per Square Inch / Population Services International) 1)PSI&#xff1a;每平方英寸磅 (1) PSI: Pound per Square Inch) PSI is an abbreviation of Pound per Square Inch. Pound per Square Inch …

jupyter notebook指定工作目錄

【1】打開Anaconda Navigator 打開Anaconda Navigator&#xff0c;點擊左側Environments&#xff0c;點擊base(root)->open Terminal 【2】輸入指令jupyter notebook --generate-config 按下回車鍵&#xff0c;彈出config所在位置。 以VS Code打開文件 【3】修改第26…

四、纖維素纖維使用P-N系阻燃劑協同作用的原理?

纖維素纖維使用P-N系阻燃劑協同作用的原理? 收集資料階段 某些含氮、磷化合物可以增強化合物的阻燃性,原因就是磷、氮在反應過程中形成含 N-P 鍵的中間體,可以改善羰基反應活性和磷酰化速率,進而提高成炭率;另一個重要的原因是氮化合物可以延緩凝聚相中含磷化合物的會揮發…

oracle tns 連接關閉,ORA-12537 TNS:連接關閉

今天遇到&#xff1a;ORA-12537 TNS&#xff1a;連接關閉&#xff0c;監聽正常&#xff0c;集群正常&#xff0c;數據庫正常&#xff0c;查了一下才發現問題。LISTENER日志報錯TNS-12546: TNS:permission deniedTNS-12560: TNS:protocol adapter errorTNS-00516: Permission de…

多模態大模型:關于RLHF那些事兒

Overview 多模態大模型關于RLHF的代表性文章一、LLaVA-RLHF二、RLHF-V三、SILKIE多模態大模型關于RLHF的代表性文章 一、LLaVA-RLHF 題目: ALIGNING LARGE MULTIMODAL MODELS WITH FACTUALLY AUGMENTED RLHF 機構:UC伯克利 論文: https://arxiv.org/pdf/2309.14525.pdf 代碼…

c# 整數類型轉byte_C#中數據類型的整數類型

c# 整數類型轉byteHere is the list of the built-in integral types of data types in C#, sbyte, byte, char, short, ushort, int, uint, long and ulong 這是C&#xff03;&#xff0c; sbyte &#xff0c; byte &#xff0c; char &#xff0c; short &#xff0c; ushort…

COM+組件注冊方法

COM組件注冊方法 有兩種方式注冊組件&#xff1a;一種是調用regsvr32.exe&#xff1a;例如我們運行regsvr32.exe c:\test.dll來注冊位于C:盤根目錄下的test.dll。另外一種是在MTS&#xff08;微軟事務服務器&#xff09;中注冊。MTS是值得推薦的&#xff0c;因為它具有下列優點…