提莫隊長蓄勢待發

2021-08-13 03:51:32 字數 1843 閱讀 8231

select * from tf_fdctze t1

where exists (select id from tf_fdctze t2 where t2.id ='33' and t1.id=t2.id)

exists 判斷條件 子查詢為true時才會執行查詢,

但是切記

與 in

沒有絕對的快慢 主要還是看你寫的子查詢裡面sql語句的水平 

select * from t  where id in(select id from t2 where id ='22' )

子查詢返回的記錄同時 外圍也是查到,類似於for迴圈 同步

例: 查到了 第5條。 子查詢也是第5條,

all 關鍵字

查詢出工資比部門30全部員工工資都高的人

select * from where sal > all( select sal from emp where detp ='30')

上述效率比較高

all 是所有的都必須符合 每比較一次 all都會全部查詢一次 

select * from where sal >all( select sal from emp where detp ='30')

查詢出工資比部門30任意乙個工資高的人 

select  * from emp where sal > (select  min(sal) from emp where delt ='30')

any 是任意的意思,

select * from emp where sal > any(select sal from emp where delt ='30')

統計每個部門的資訊和人數

select d.*(select count(1) from emp s  where s.id = d.id ) from  dept d

統計每個部門工資在 500-100。1000-3000 3000-5000的人數

select d.*,

(select count(*)  from emp e  where e.deptno = d.deptno and sal >500 and sal <= 1000) ' 500-1000',

from dept d

count(*) 與 count(1) 區別  本質上沒有區別,* 與 1 * 是查詢所有的列 而 1 是查詢非空。如果有空是跳過的

內聯子查詢

rownum 是 oracle 對結果集加的乙個偽劣通常用來排序時。使用

select e.*,rownum from emp e

select e.*,rownum from (select * from emp )e

rownum是針對結果集來的 他在order by執行順序之前,所以rownum 會亂掉

select e.*,rownum from emp order by sal      -- 此時rownum會亂掉。但是 上面例子外的 rownum卻不會亂掉

(rownum  必須從1 開始。。)

select e.* rownum  from (select  * rownum from emp order by sal ) e where rownum <=5 

查詢出在6到10之間的

select  * from (select e.* rownum  rf from (select  * from emp  ) e where e.rownum <=10) e2

where  e2.rf > 5

API經濟蓄勢待發

bessemer venture partners的合夥人byron deeter近日在vb撰文 不到十年時間,曾經鮮為人知的api 應用程式介面 已經進化成軟體開發 業務合作乃至商業模式創新不可或缺的 數字膠水 圍繞api的b2d business to developer 市場正在成為雲計算大潮...

Windows Mobile 6 蓄勢待發

前段時間寫了 windows mobile crossbow詳盡評測 和 windows mobile crossbow 預覽 兩篇隨筆,傳達 windows mobile crossbow 的最新訊息和評測。現在已經確定正式命名為 windows mobile 6,即使它的核心並非 windows...

CMMB蓄勢待發,模擬電視東山再起

在國家廣電總局宣布cmmb將於2009年7月正式試商用之際,一股拓展模擬手機電視的浪潮正在中國本土積體電路設計業興起,據老杳所知,已經在售和正在研發的本土積體電路設計企業有五家之多,憑藉這些具有強大市場推力的本土企業推波助瀾,相信2009年下半年伴隨cmmb的試商用,模擬手機電視在中國本土會東山再起...