回复:超級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”