回複:超級SQL STATEMENT問題(請求天才)....

來源: o.oooo1 2010-02-21 10:36:54 [] [舊帖] [給我悄悄話] 本文已被閱讀: 次 (1221 bytes)
Yours does work.
However,it was quite mind-binding (you ARE genius!).
I have a something which I tested and may be easier to understand:
with test_table as
(


select 'mike' name, 'computer' gadget from dual union all
select 'mike', 'computer' from dual union all
select 'mike', 'keyboard' from dual union all
select 'mike', 'mouse' from dual union all
select 'steve', 'computer' from dual union all
select 'steve', 'phone' from dual union all
select 'anton', 'computer' from dual union all
select 'anton', 'keyboard' from dual union all
select 'anton', 'mouse' from dual union all
select 'anton', 'TV' from dual union all
select 'alex', 'TV' from dual union all
select 'alex', 'mouse' from dual union all
select 'alex', 'phone' from dual union all
select 'alex', 'computer' from dual
)
SELECT t1.NAME, COUNT(*) FROM
(SELECT name,gadget FROM test_table WHERE NAME != 'steve') t1,

(SELECT name, gadget FROM test_table WHERE NAME = 'steve') t2
WHERE t1.gadget = t2.gadget
GROUP BY t1.NAME
HAVING COUNT(*) = (SELECT COUNT(DISTINCT gadget) FROM test_table WHERE NAME = 'steve')
請您先登陸,再發跟帖!

發現Adblock插件

如要繼續瀏覽
請支持本站 請務必在本站關閉/移除任何Adblock

關閉Adblock後 請點擊

請參考如何關閉Adblock/Adblock plus

安裝Adblock plus用戶請點擊瀏覽器圖標
選擇“Disable on www.wenxuecity.com”

安裝Adblock用戶請點擊圖標
選擇“don't run on pages on this domain”