当我有选择关键字时,缺少选择关键字错误


 (select course_id
 from section
 where semester = 'FALL' AND  year = 2009)
  intersect all 
 (select course_id
 from section
 where semester = 'SPRING' AND  YEAR = 2010);

我正在阅读Henry Korth的数据库系统概念.我正在尝试完全按照书中的内容进行交叉,但是当我有选择关键字时,我遇到了缺少选择关键字错误。

编辑:看起来只有当我使用"全部相交"但"相交"工作正常时,我才收到错误

您不要在 Oracle 中使用带有INTERSECTALL部分。 ALLUNION一起使用,而不是与INTERSECTMINUS一起使用。试试没有...(括号也是不必要的,它们不会伤害任何东西,只是不需要(:

select course_id
from section
where semester = 'FALL' AND  year = 2009
intersect
select course_id
from section
where semester = 'SPRING' AND  YEAR = 2010;

显然PostgreSQL支持ALL INTERSECT,但Oracle不支持。我确实看到了可以使用以下内容来模仿它的位置:

with intersect_tbl as
(
    select course_id, row_number(partition by course_id) as rnum
    from section
    where semester = 'FALL' AND  year = 2009
    intersect
    select course_id, row_number(partition by course_id) as rnum
    from section
    where semester = 'SPRING' AND  YEAR = 2010
)
select course_id
from intersect_tbl;

既然你提到你找到你的例子的书是由你的学校分配的,我会和他们澄清你是否应该在你的班级中使用一个特定的DBMS。正如我提到的INTERSECT ALLPostgreSQL 中可用,因此他们可能打算让您使用该口味而不是Oracle

最新更新