2013-02-01 64 views

回答

0

Fiddle link for sample query execution

create table schedule (course varchar2(10),day varchar2(20)); 
insert into schedule values('A','MONDAY'); 
insert into schedule values('A','WEDNESDAY'); 
insert into schedule values('B','MONDAY'); 
insert into schedule values('C','WEDNESDAY'); 

select s1.course 
from 
    schedule s1,schedule s2 
where 
    s1.course=s2.course 
AND 
    s1.day='MONDAY' 
AND 
    s2.day='WEDNESDAY'; 

輸出

| COURSE | 
---------- 
|  A | 
+0

非常感謝你 –

2

這種類型的問題稱爲關係司。

SELECT course 
FROM tableName 
WHERE day IN ('Monday', 'Wednesday') 
GROUP BY course 
HAVING COUNT(*) = 2 

的解決方案比使用加入,因爲查詢的結構甚至不會有另一個條件變化更加靈活。 如果您想搜索三個值,該怎麼辦?你會提供另一個連接嗎?那麼這個查詢,僅值會發生變化,

其他來源(S):