SQL的all、any和some的用法
SQL的all、any和some的用法
1、首先t1和t2表如下:? ?t1(2,3)? ? ? ? ? ? ? ? ? ? ? ? ? ? t2(1,2,3,4)
2、all,any,some 的子查詢
2.1 all 父查詢中的結果集大于子查詢中每一個結果集中的值,則為真
select * from t2 where n>all (select n from t1)? ? ? ?---4
2.2 any,some 父查詢中的結果集大于子查詢中任意一個結果集中的值,則為真
select * from t2 where n>any(select n from t1)? ? ? --3 4
select * from t2 where n>some(select n from t1)? ?--3 4
2.3 any 與子查詢in相同
select * from t2 where n=any (select n from t1) ? ---2 3
xxselect * from t2 where n in (select n from t1) ? ?---dsd2 3
2.4 any 與not in?
1)any
or作用 父查詢中的結果集不等于子查詢中的a或者b或者c,則為真
select * from t2 where n <>any(select * from t1) -----1 2 3 4
2)not in
--and作用 父查詢中的結果集不等于子查詢中任意一個結果集中的值,則為真
select * from t2 where n not in(select * from t1) ?---1 4
總結
以上是生活随笔為你收集整理的SQL的all、any和some的用法的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: js some every数组方法的区别
- 下一篇: 非知名猎头Henry 和你谈-高薪是怎么