我刚刚开始学习数据库和SQL,我一直在研究一个我无法解决的问题。这是我尝试做的,给出了两个名为CHARTER和CUSTOMER的表:
Give the relational algebra statement (or SQL) as well as the table that would
result from applying SELECT & JOIN relational operators to the CHARTER and
CUSTOMER tables to return only the CHAR_TRIP, CUS_LNAME and CHAR_DESTINATION
attributes for charters flown by pilot 109.
Note that 109 is sometimes the pilot and other times the co-pilot.
Display all these flights.
这是我尝试过的SQL:
select CHAR_TRIP, CUS_LNAME, CHAR_DESTINATION from CHARTER natural join CUSTOMER where CHARTER.CHAR_PILOT and CHARTER.CHAR_COPILOT="109";
但这似乎并没有给我我想要的东西;我应该得到6条记录,但我只得到3.我认为这可能是由于SQL中的某些内容。我是否忽略了我的代码?
答案 0 :(得分:0)
不确定Mysql是否有一些特殊语法,但尝试分离WHERE条件:
select CHAR_TRIP, CUS_LNAME, CHAR_DESTINATION
from CHARTER natural join CUSTOMER
where CHARTER.CHAR_PILOT ="109"
or CHARTER.CHAR_COPILOT="109";
我将第二个更改为or
,因为109可以是主要飞行员或副驾驶员。