谁能告诉我下面这个查询有什么问题?从编程的角度来看,它非常有意义,但 sql 似乎并不喜欢它。
选择 SNAME,YEAR,GPA 从学生
WHERE (YEAR >= 5 AND GPA <=3.0) AND (WHERE YEAR <=4 AND GPA <= 2.0)
ORDER BYYEAR, GPA DESC ;
我收到此错误:
第 2 行出现错误 ORA-00936:缺少表达式
问题是您的查询中有两个WHERE
子句。
此外,您应该使用OR
运算符而不是 a组合两个布尔表达式AND
,以便在满足两者中的任何一个时完整的表达式为真:
SELECT SNAME, YEAR, GPA
FROM STUDENT
WHERE (YEAR >= 5 AND GPA <=3.0) OR (YEAR <=4 AND GPA <= 2.0)
ORDER BY YEAR, GPA DESC ;
删除条件中的额外WHERE
关键字。
SELECT SNAME, YEAR, GPA
FROM STUDENT
WHERE (YEAR >= 5 AND GPA <=3.0) Or (YEAR <=4 AND GPA <= 2.0)
ORDER BY YEAR, GPA DESC
尝试将其更改为
SELECT SNAME,
YEAR,
GPA
FROM STUDENT
WHERE (YEAR >= 5 AND GPA <=3.0)
OR (YEAR <=4 AND GPA <= 2.0)
ORDER BY YEAR, GPA DESC ;
您指定了KEYWORD WHERE
两次。
在 sql 中,仅在查询中使用条件的一次:
SELECT SNAME, YEAR, GPA
FROM STUDENT
WHERE (YEAR >= 5 AND GPA <=3.0) OR (YEAR <=4 AND GPA <= 2.0)
ORDER BY YEAR, GPA DESC ;
有关详细信息,请遵循语法:
how the rows in the result set will be sorted. This clause is optional.
Description
You use the basic SELECT statement shown above to retrieve the
columns specified in the SELECT clause from the base table specified
in the FROM clause and store them in a result set.
The WHERE clause is used to filter the rows in the base table so that
only those rows that match the search condition are included in the
result set. If you omit the WHERE clause, all of the rows in the base
table are included.
The search condition of a WHERE clause consists of one or more Boolean
expressions, or predicates, that result in a value of True, False, or
Unknown. If the combination of all the expressions is True, the row
being tested is included in the result set. Otherwise, it's not.
If you include the ORDER BY clause, the rows in the result set are
sorted in the specified sequence. Otherwise, the sequence of the rows
is not guaranteed by Oracle. Note
The syntax shown above does not include all of the clauses
of the SELECT statement. You'll learn about the other clauses later in this book.