Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/unit-testing/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ionic-framework/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql 尝试模拟交叉口时出错_Sql_Oracle12c - Fatal编程技术网

Sql 尝试模拟交叉口时出错

Sql 尝试模拟交叉口时出错,sql,oracle12c,Sql,Oracle12c,我试图模仿这个问题(出于学术目的) 成功模仿 select t.course_id from section t, section s where s.course_id = t.course_id and s.semester = 'Spring' and s.year = 2010 and t.semester = 'Fall' and t.year = 2009; 当我尝试这些时 select t.course_id from section t, section s where s.c

我试图模仿这个问题(出于学术目的)

成功模仿

select t.course_id from section t, section s where s.course_id = t.course_id and
s.semester = 'Spring' and s.year = 2010 and t.semester = 'Fall' and t.year = 2009;
当我尝试这些时

select t.course_id from section t, section s where s.course_id = t.course_id and
(s.semester, s.year, t.semester,t.year) in ('Spring',2010,'Fall',2009);
谓词中
后括号处出错(根据行和
错误中提到的列),错误为ORA-00920:无效关系
操作人员
92000000-“无效的关系运算符”

然后我试着

select t.course_id from section t, section s where 
s.course_id = t.course_id and (s.semester,s.year) = ('Spring',2010) 
and (t.semester, t.year) in ('Fall',2009);


select t.course_id from section t, section s where 
s.course_id = t.course_id and ((s.semester,s.year) in ('Spring',2010)) 
and ((t.semester, t.year) = ('Fall',2009));
使用
中的
=的不同组合,在或=中第一个
后的括号中得到相同的错误

在/=(…)
中提及
(…)的属性有限制吗?或者使用相同的表会导致这种情况还是其他原因

使用Oracle 12c。

首先停止使用“逗号连接语法”。它已经过时,并且有一个伟大的后继者,名为
JOIN
。您可以在此处阅读更多:

其次,您需要用另一对圆括号来包装您的值:

SELECT t.course_id 
FROM section t 
JOIN section s 
  ON s.course_id = t.course_id
WHERE (s.semester, s.year, t.semester,t.year) IN (('Spring',2010,'Fall',2009));

您可能会问“为什么我需要额外的圆括号?”,请思考
子句中的
中的多个值:

WHERE (col1, col2, col3, col4) IN ((1,2,3,4), (5,6,7,8), (9,10,11,12))
您的困惑可能是由单一值引起的,例如:

WHERE col IN (1,2,3);
<=>
WHERE (col) IN ((1), (2), (3));  
其中col在(1,2,3)中;
其中((1)、(2)、(3)中的(col);

逗号连接或交叉连接与just join不同。@我指的是t节、s节中的
,其中s.course\u id=t.course\u id
where
子句中进行连接。当然,如果没有
WHERE
,您将获得笛卡尔积。@lad2025您可以参考任何提供SQL深入知识的书籍吗,oracle文档对于您来说太先进了me@Sab我推荐Jason Price的《Oracle Database 12c SQL》和Michael McLaughlin的《Oracle Database 12c PL/SQL编程》
WHERE col IN (1,2,3);
<=>
WHERE (col) IN ((1), (2), (3));