日本免费高清视频-国产福利视频导航-黄色在线播放国产-天天操天天操天天操天天操|www.shdianci.com

學無先后,達者為師

網站首頁 編程語言 正文

子查詢關鍵字-ALL、ANY、SOME、IN、EXISTS

作者:TimeFriends 更新時間: 2022-05-20 編程語言

子查詢關鍵字-ALL、ANY、SOME、IN、EXISTS

ALL
select from where c > all(查詢語句)
等價于
select from where c > result1 and c > result2 and c > result3

特點:
	1:all與子查詢返回的所有值比較為true 則返回true
	2:ALL可以與= > < >= <= <>結合使用
	3:all表示指定列中的值必須要大于子查詢集中的每一個值
eg:查詢年齡大于'1003'部門所有年齡的員工信息
select * from emp3 where age > all(select age from emp3 where dept_id='1003');
   查詢不屬于任何一個部門的員工信息
select * from emp3 where dept_id != all(select deptno from dept3);
ANY SOME
select from where c > any(查詢語句)
等價于
select from where c > result1 or c > result2 or c > result3

特點:
	1:any與子查詢返回的所有值比較為true 則返回true
	2:any可以與= > < >= <= <>結合使用
	3:any表示指定列中的值要大于子查詢集中任意的一個值
eg:查詢年齡大于'1003'部門任意一個員工年齡的員工信息
select * from emp3 where age > any(select age from emp3 where dept_id='1003');
 
some和any的作用是一樣的,some可以理解為是any的別名
IN
select from c in (查詢語句)
等價于
select from where c =result1 or c=result2 or c=result3

特點:
	in關鍵字,用于判斷某個記錄的值,是否在指定的集合中
	在in關鍵字前面加上not可以將條件反過來
eg:查詢研發部和銷售部的員工信息,包括員工工號,員工名字
select c.cid,c.name from cmp3 c where dept_id in (select deptno from dept3 where name='研發部' or name='銷售部');
EXISTS
select from where exists(查詢語句)
    
特點:
	該子查詢如果"有數據結果"(至少返回一行數據),則該EXISTS()的結果為true 外層查詢執行
	該子查詢如果"沒有數據結果"(沒有任何數據返回),則該EXISTS()的結果為false 外層查詢不執行
	注意:EXISTS關鍵字,比in關鍵字的運算效率高,在實際開發中 特別是數據量大的時候推薦使用exists關鍵字

eg:查詢公司是否有大于60歲的員工,有則輸出
select * from epm3 a where exists (select * from emp3 b where a.age>60)
查詢所屬部門的員工信息
select *from dept3 a where exists (select * from emp3 b where a.deptno=b.dept_id)

原文鏈接:https://timefriends.blog.csdn.net/article/details/123676775

欄目分類
最近更新