锘??xml version="1.0" encoding="utf-8" standalone="yes"?>亚洲伦理中文字幕,亚洲精品GV天堂无码男同,亚洲中文字幕无码一区http://www.tkk7.com/hmily1211/category/19536.htmlzh-cnTue, 27 Feb 2007 12:33:25 GMTTue, 27 Feb 2007 12:33:25 GMT60IN OR EXISTS IT IS A QUESTTION. (QUOTE)http://www.tkk7.com/hmily1211/articles/96154.html媧誨湪JAVA宀涚殑鏃ュ瓙媧誨湪JAVA宀涚殑鏃ュ瓙Fri, 26 Jan 2007 06:55:00 GMThttp://www.tkk7.com/hmily1211/articles/96154.htmlhttp://www.tkk7.com/hmily1211/comments/96154.htmlhttp://www.tkk7.com/hmily1211/articles/96154.html#Feedback0http://www.tkk7.com/hmily1211/comments/commentRss/96154.htmlhttp://www.tkk7.com/hmily1211/services/trackbacks/96154.html鏈夋椂鍊欎細灝嗕竴鍒楀拰涓緋誨垪鍊肩浉姣旇緝銆傛渶綆鍗曠殑鍔炴硶灝辨槸鍦╳here瀛愬彞涓嬌鐢ㄥ瓙鏌ヨ銆傚湪where瀛愬彞涓彲浠ヤ嬌鐢ㄤ袱縐嶆牸寮忕殑瀛愭煡璇€?

絎竴縐嶆牸寮忔槸浣跨敤IN鎿嶄綔絎︼細

... where column in(select * from ... where ...);

絎簩縐嶆牸寮忔槸浣跨敤EXIST鎿嶄綔絎︼細

... where exists (select 'X' from ...where ...);

鎴戠浉淇$粷澶у鏁頒漢浼氫嬌鐢ㄧ涓縐嶆牸寮忥紝鍥犱負瀹冩瘮杈冨鏄撶紪鍐欙紝鑰屽疄闄呬笂絎簩縐嶆牸寮忚榪滄瘮絎竴縐嶆牸寮忕殑鏁堢巼楂樸傚湪Oracle涓彲浠ュ嚑涔庡皢鎵鏈夌殑IN鎿嶄綔絎﹀瓙鏌ヨ鏀瑰啓涓轟嬌鐢‥XISTS鐨勫瓙鏌ヨ銆?

絎簩縐嶆牸寮忎腑錛屽瓙鏌ヨ浠モ榮elect 'X'寮濮嬨傝繍鐢‥XISTS瀛愬彞涓嶇瀛愭煡璇粠琛ㄤ腑鎶藉彇浠涔堟暟鎹畠鍙煡鐪媤here瀛愬彞銆傝繖鏍蜂紭鍖栧櫒灝變笉蹇呴亶鍘嗘暣涓〃鑰屼粎鏍規嵁绱㈠紩灝卞彲瀹屾垚宸ヤ綔錛堣繖閲屽亣瀹氬湪where璇彞涓嬌鐢ㄧ殑鍒楀瓨鍦ㄧ儲寮曪級銆傜浉瀵逛簬IN瀛愬彞鏉ヨ錛孍XISTS浣跨敤鐩歌繛瀛愭煡璇紝鏋勯犺搗鏉ヨ姣擨N瀛愭煡璇㈠洶闅句竴浜涖?

閫氳繃浣跨敤EXIST錛孫racle緋葷粺浼氶鍏堟鏌ヤ富鏌ヨ錛岀劧鍚庤繍琛屽瓙鏌ヨ鐩村埌瀹冩壘鍒扮涓涓尮閰嶉」錛岃繖灝辮妭鐪佷簡鏃墮棿銆侽racle緋葷粺鍦ㄦ墽琛孖N瀛愭煡璇㈡椂錛岄鍏堟墽琛屽瓙鏌ヨ錛屽茍灝嗚幏寰楃殑緇撴灉鍒楄〃瀛樻斁鍦ㄥ湪涓涓姞浜嗙儲寮曠殑涓存椂琛ㄤ腑銆傚湪鎵ц瀛愭煡璇箣鍓嶏紝緋葷粺鍏堝皢涓繪煡璇㈡寕璧鳳紝寰呭瓙鏌ヨ鎵ц瀹屾瘯錛屽瓨鏀懼湪涓存椂琛ㄤ腑浠ュ悗鍐嶆墽琛屼富鏌ヨ銆傝繖涔熷氨鏄嬌鐢‥XISTS姣斾嬌鐢↖N閫氬父鏌ヨ閫熷害蹇殑鍘熷洜銆?

鍚屾椂搴斿敖鍙兘浣跨敤NOT EXISTS鏉ヤ唬鏇縉OT IN錛屽敖綆′簩鑰呴兘浣跨敤浜哊OT錛堜笉鑳戒嬌鐢ㄧ儲寮曡岄檷浣庨熷害錛夛紝NOT EXISTS瑕佹瘮NOT IN鏌ヨ鏁堢巼鏇撮珮銆?br />
EXISTS媯鏌ユ槸鍚︽湁緇撴灉錛屽垽鏂槸鍚︽湁璁板綍錛岃繑鍥炵殑鏄竴涓竷灝斿瀷錛圱RUE/FALSE錛夈?br />IN鏄緇撴灉鍊艱繘琛屾瘮杈冿紝鍒ゆ柇涓涓瓧孌墊槸鍚﹀瓨鍦ㄤ簬鍑犱釜鍊肩殑鑼冨洿涓紝鎵浠?EXISTS 姣?IN 蹇?/p>


涓昏鍖哄埆鏄?
exists涓昏鐢ㄤ簬鐗囬潰鐨?鏈夋弧瓚充竴涓潯浠剁殑鍗沖彲,
in涓昏鐢ㄤ簬鍏蜂綋鐨勯泦鍚堟搷浣?鏈夊灝戞弧瓚蟲潯浠?

exists鏄垽鏂槸鍚﹀瓨鍦ㄨ繖鏍風殑璁板綍錛?br />in鏄垽鏂煇涓瓧孌墊槸鍚﹀湪鎸囧畾鐨勬煇涓寖鍥村唴銆?br />exists蹇竴浜涘惂 銆?/p>


in閫傚悎鍐呭琛ㄩ兘寰堝ぇ鐨勬儏鍐碉紝exists閫傚悎澶栬〃緇撴灉闆嗗緢灝忕殑鎯呭喌銆?/p>


鍦ˋSKTOM鐨勮瑙o細
Well, the two are processed very very differently.

Select * from T1 where x in ( select y from T2 )

is typically processed as:

select *
from t1, ( select distinct y from t2 ) t2
where t1.x = t2.y;

The subquery is evaluated, distinct'ed, indexed (or hashed or sorted) and then
joined to the original table -- typically.


As opposed to

select * from t1 where exists ( select null from t2 where y = x )

That is processed more like:


for x in ( select * from t1 )
loop
if ( exists ( select null from t2 where y = x.x )
then
OUTPUT THE RECORD
end if
end loop

It always results in a full scan of T1 whereas the first query can make use of
an index on T1(x).


So, when is where exists appropriate and in appropriate?

Lets say the result of the subquery
( select y from T2 )

is "huge" and takes a long time. But the table T1 is relatively small and
executing ( select null from t2 where y = x.x ) is very very fast (nice index on
t2(y)). Then the exists will be faster as the time to full scan T1 and do the
index probe into T2 could be less then the time to simply full scan T2 to build
the subquery we need to distinct on.


Lets say the result of the subquery is small -- then IN is typicaly more
appropriate.


If both the subquery and the outer table are huge -- either might work as well
as the other -- depends on the indexes and other factors.



]]>
EXISTS and NOT EXISTShttp://www.tkk7.com/hmily1211/articles/96153.html媧誨湪JAVA宀涚殑鏃ュ瓙媧誨湪JAVA宀涚殑鏃ュ瓙Fri, 26 Jan 2007 06:45:00 GMThttp://www.tkk7.com/hmily1211/articles/96153.htmlhttp://www.tkk7.com/hmily1211/comments/96153.htmlhttp://www.tkk7.com/hmily1211/articles/96153.html#Feedback0http://www.tkk7.com/hmily1211/comments/commentRss/96153.htmlhttp://www.tkk7.com/hmily1211/services/trackbacks/96153.html EXISTS and NOT EXISTS

If a subquery returns any values at all, then EXISTS <subquery> is TRUE, and NOT EXISTS <subquery> is FALSE. For example:

SELECT column1 FROM t1 WHERE EXISTS (SELECT * FROM t2);

Traditionally an EXISTS subquery starts with SELECT * but it could begin with SELECT 5 or SELECT column1 or anything at all -- MySQL ignores the SELECT list in such a subquery, so it doesn't matter.

For the above example, if t2 contains any rows, even rows with nothing but NULL values, then the EXISTS condition is TRUE. This is actually an unlikely example, since almost always a [NOT] EXISTS subquery will contain correlations. Here are some more realistic examples.

Example: What kind of store is present in one or more cities?

SELECT DISTINCT store_type FROM Stores
  WHERE EXISTS (SELECT * FROM Cities_Stores
                WHERE Cities_Stores.store_type = Stores.store_type);

Example: What kind of store is present in no cities?

SELECT DISTINCT store_type FROM Stores
  WHERE NOT EXISTS (SELECT * FROM Cities_Stores
                    WHERE Cities_Stores.store_type = Stores.store_type);

Example: What kind of store is present in all cities?

SELECT DISTINCT store_type FROM Stores S1
  WHERE NOT EXISTS (
    SELECT * FROM Cities WHERE NOT EXISTS (
      SELECT * FROM Cities_Stores
       WHERE Cities_Stores.city = Cities.city
       AND Cities_Stores.store_type = Stores.store_type));

The last example is a double-nested NOT EXISTS query -- it has a NOT EXISTS clause within a NOT EXISTS clause. Formally, it answers the question ``does a city exist with a store which is not in Stores?''. But it's easier to say that a nested NOT EXISTS answers the question ``is x TRUE for all y?''.



]]>
主站蜘蛛池模板: 18成禁人视频免费网站| 四虎影视永久在线精品免费| 久草福利资源网站免费| 亚洲无av在线中文字幕| 成全视频免费观看在线看| 亚洲欧洲∨国产一区二区三区| 拍拍拍无挡免费视频网站| 国产亚洲精品看片在线观看| 有码人妻在线免费看片| 日韩一卡2卡3卡4卡新区亚洲| 好男人资源在线WWW免费| 亚洲av永久无码精品漫画| 久久久久久影院久久久久免费精品国产小说| 国产亚洲成av人片在线观看| 成在人线av无码免费高潮喷水| 亚洲av无码乱码国产精品 | 一级毛片免费在线观看网站| 亚洲成aⅴ人片久青草影院| 国产免费黄色无码视频| 国产亚洲精品xxx| 57pao国产成永久免费视频| 亚洲免费人成视频观看| 日本不卡免费新一二三区| 欧洲乱码伦视频免费国产 | 亚洲伊人久久精品| 精品国产麻豆免费网站| 一边摸一边爽一边叫床免费视频 | 亚洲综合色自拍一区| 久久青草免费91观看| 亚洲性无码一区二区三区| 亚洲国产成人精品久久久国产成人一区二区三区综 | 亚洲六月丁香六月婷婷色伊人 | 亚洲人成人网毛片在线播放| 国产乱子伦精品免费无码专区| 久久免费99精品国产自在现线| 亚洲精品高清国产一久久| 欧洲美熟女乱又伦免费视频| 在线观看免费无码视频| 亚洲乱码在线卡一卡二卡新区| 国产成人亚洲影院在线观看| 最近中文字幕大全免费视频|