语法类似于MySQL中的除外

时间:2013-12-15 07:45:05

标签: mysql phpmyadmin

我的查询需要执行以下操作:

  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语句无效,因为它会给我一个不同的结果。

1 个答案:

答案 0 :(得分: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 )