下面的查询工作正常并给出结果A,B,C
SELECT winner
FROM nobel_win
WHERE (SUBJECT='Economics' AND Year=1971 );
此外,下面的查询工作正常并给出D,E,F
SELECT winner
FROM nobel_win
WHERE (SUBJECT='Physics' AND Year=1970 );
我想在一个WHERE条件下使它们得到结果A,B,D,E,F但它失败
SELECT winner
FROM nobel_win
WHERE (SUBJECT='Physics' AND Year=1970 )
OR (SUBJECT='Economics' AND Year=1971);
在集合论中,联合会为您提供综合结果。这就是我使用OR的原因。
来源
https://www.w3resource.com/sql-exercises/sql-retrieve-from-table.php#SQLEDITOR
由于
答案 0 :(得分:2)
我认为他们的在线查询工具SQLEDITOR包含错误:
https://www.w3resource.com/sql-exercises/sql-retrieve-from-table.php#SQLEDITOR
当我尝试进行OR查询时,出现了一些奇怪的错误:请求存在问题。
如果你在他们的页面上运行 REPORT zitab_siddhi.
TYPES: BEGIN OF EMPLOYEE,
EMPID TYPE C,
EMPNAME TYPE string,
EMPADDRESS TYPE c,
EMPEMAIL TYPE c,
EMPDEPT TYPE c,
EMPROLE TYPE string,
EMPCONT TYPE C,
END OF employee.
TYPES ITAB_EMPLOYEE TYPE STANDARD TABLE OF EMPLOYEE.
DATA: ITAB_EMPLOYEE_I TYPE EMPLOYEE.
ITAB_EMPLOYEE_I-EMPID = '123'.
ITAB_EMPLOYEE_I-EMPNAME = 'JOHN DOE'.
ITAB_EMPLOYEE_I-EMPADDRESS = 'BANGALORE'.
ITAB_EMPLOYEE_I-EMPEMAIL = 'JOHN@BANGALORE.COM'.
ITAB_EMPLOYEE_I-EMPDEPT = 'SALES'.
ITAB_EMPLOYEE_I-EMPROLE = 'MANAGER'.
ITAB_EMPLOYEE_I-EMPCONT = '1234567890'.
APPEND ITAB_EMPLOYEE_I TO ITAB_EMPLOYEE.
,然后将整个结果(整个SELECT * FROM nobel_win
表)复制到另一个工具,如SQLFiddle,那么一切都很好,请看下面的演示:
http://sqlfiddle.com/#!9/f33d08/3
只是不要使用他们的错误在线工具来学习这些东西,而是使用一些真正的数据库。
如果您更喜欢在线工具,并且不愿意在计算机上安装真实数据库,请使用SQLFiddle或DBFiddle。
nobel_win
SELECT winner
FROM nobel_win
WHERE (SUBJECT='Economics' AND Year=1971 );
| winner |
|---------------|
| Simon Kuznets |
SELECT winner
FROM nobel_win
WHERE (SUBJECT='Physics' AND Year=1970 );
| winner |
|---------------|
| Hannes Alfven |
| Louis Neel |