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

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')

請您先登陸,再發跟帖!