2013-12-15 89 views
1
除外

我的查詢需要做到以下幾點:語法類似於MySQL的

SELECT 
    c1.building, 
    c1.room_number 
FROM 
    time_slot AS t, 
    section AS s, 
    classroom AS c1 
WHERE c1.capacity > 30 
    AND s.semester = 'Fall' 
    AND s.year = '2009' 
    AND t.day = 'M' 
    AND t.start_hr < 12 EXCEPT 
    SELECT 
    c1.building, 
    c1.room_number 
    FROM 
    time_slot AS t, 
    section AS s NATURAL 
    JOIN classroom AS c1 
    WHERE c1.capacity > 30 
    AND s.semester = 'Fall' 
    AND s.year = '2009' 
    AND t.day = 'M' 
    AND t.start_hr < 12 

它返回從沒有在秋季上週一的佔領中午前教室表中的所有建築名稱和房間號2009學期。更改where語句是無效的,因爲它給了我不同的結果。

+0

'time_slot'與'section'和/或'classroom'有什麼關係? – peterm

+0

我很抱歉不清楚。 –

+0

教室(建築,room_number,容量) 部分(COURSE_ID,sec_id,學期一年,建築,room_number,time_slot_id) TIME_SLOT(time_slot_id,日,START_HR,start_min,end_hr,end_min) –

回答

0
SELECT 
    c1.building, 
    c1.room_number 
FROM 
    time_slot AS t, 
    section AS s, 
    classroom AS c1 
WHERE c1.capacity > 30 
    AND s.semester = 'Fall' 
    AND s.year = '2009' 
    AND t.day = 'M' 
    AND t.start_hr < 12 and (c1.building, 
    c1.room_number) not in (
    SELECT 
    c1.building, 
    c1.room_number 
    FROM 
    time_slot AS t, 
    section AS s NATURAL 
    JOIN classroom AS c1 
    WHERE c1.capacity > 30 
    AND s.semester = 'Fall' 
    AND s.year = '2009' 
    AND t.day = 'M' 
    AND t.start_hr < 12)