锘??xml version="1.0" encoding="utf-8" standalone="yes"?>亚洲伦理中文字幕,亚洲精品GV天堂无码男同,亚洲中文字幕无码一区http://m.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://m.tkk7.com/hmily1211/articles/96154.html媧誨湪JAVA宀涚殑鏃ュ瓙媧誨湪JAVA宀涚殑鏃ュ瓙Fri, 26 Jan 2007 06:55:00 GMThttp://m.tkk7.com/hmily1211/articles/96154.htmlhttp://m.tkk7.com/hmily1211/comments/96154.htmlhttp://m.tkk7.com/hmily1211/articles/96154.html#Feedback0http://m.tkk7.com/hmily1211/comments/commentRss/96154.htmlhttp://m.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://m.tkk7.com/hmily1211/articles/96153.html媧誨湪JAVA宀涚殑鏃ュ瓙媧誨湪JAVA宀涚殑鏃ュ瓙Fri, 26 Jan 2007 06:45:00 GMThttp://m.tkk7.com/hmily1211/articles/96153.htmlhttp://m.tkk7.com/hmily1211/comments/96153.htmlhttp://m.tkk7.com/hmily1211/articles/96153.html#Feedback0http://m.tkk7.com/hmily1211/comments/commentRss/96153.htmlhttp://m.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?''.



]]>
主站蜘蛛池模板: 日本片免费观看一区二区| 中文字幕免费在线看| 亚洲综合免费视频| 久久亚洲中文字幕精品有坂深雪| 日韩久久无码免费毛片软件| 免费永久看黄在线观看app| 亚洲国产成人AV网站| 久久精品国产亚洲av四虎| 一级毛片人与动免费观看| 亚洲视频在线精品| 精品久久久久久国产免费了| 激情97综合亚洲色婷婷五 | 妞干网手机免费视频| 亚洲五月综合网色九月色| 无码国产精品一区二区免费I6| 99999久久久久久亚洲| 免费无码AV片在线观看软件| 亚洲欧美黑人猛交群| 国产伦精品一区二区三区免费下载 | 亚洲国产精品美女| 日韩一区二区a片免费观看| 亚洲精品无AMM毛片| 免费一级大黄特色大片| 亚洲va久久久噜噜噜久久狠狠| 久久久久久影院久久久久免费精品国产小说| 最新免费jlzzjlzz在线播放| 亚洲国产精品无码久久98| 亚洲国产精品人人做人人爽| 成人久久免费网站| 亚洲精品韩国美女在线| 成人免费a级毛片无码网站入口| 国产亚洲精品免费| 亚洲av伊人久久综合密臀性色| 18女人腿打开无遮掩免费| 亚洲中文字幕久久精品无码A | 国产好大好硬好爽免费不卡| 国产精品亚洲综合五月天| 亚洲国产成人爱av在线播放| 未满十八18禁止免费无码网站| 中文字幕亚洲情99在线| 久久国产成人精品国产成人亚洲|