select 所有降落在马略卡岛帕尔马或巴塞罗那但不是同时降落的乘客
select all passengers that landed in Palma de Mallorca or Barcelona but not both
我必须创建一个满足以下要求的语句:
Provide a list of all passengers who have landed either at the airport "Palma de Mallorca" or in "Barcelona". But by no means on both.
使用此数据库:
Flughafen-database
这是我想出的:
select *
from person
join passagierliste using (personid)
join flug using (flugid)
join flughafen on flug.flughafen_destination=flughafen.flughafenid
where (flughafenid = 'Palma de Mallorca') xor (flughafenid = 'Barcelona')
;
但这会引发以下错误:
An error occurred when executing the SQL command:
select *
from person
join passagierliste using (personid)
join flug using (flugid)
join flughafen on flug.flughafen_...
ORA-00933: SQL command not properly ended [SQL State=42000, DB Errorcode=933]
Execution time: 0.03s
1 statement(s) failed.
更新
发现错误但不是错误(我应该使用 bezeichnung 而不是 flughafenid:
select *
from person
join passagierliste using (personid)
join flug using (flugid)
join flughafen on flug.flughafen_destination=flughafen.flughafenid
where (bezeichnung = 'Palma de Mallorca') xor (bezeichnung = 'Barcelona')
;
您可以按 personid 分组并计算组中不同的描述 (bezeichnung)。由于 WHERE
子句,您知道只选择了马略卡岛或巴塞罗那的描述。这意味着如果每个人有超过 1 个不同的描述,那么他们都访问过。将此(未经测试)用作 CTE 或子查询以从 person
table.
获取相关数据
select person.personid
from person
join passagierliste using (personid)
join flug using (flugid)
join flughafen on flug.flughafen_destination=flughafen.flughafenid
where bezeichnung IN('Palma de Mallorca', 'Barcelona')
group by person.personid
having count(distinct bezeichnung) = 1
我必须创建一个满足以下要求的语句:
Provide a list of all passengers who have landed either at the airport "Palma de Mallorca" or in "Barcelona". But by no means on both.
使用此数据库: Flughafen-database
这是我想出的:
select *
from person
join passagierliste using (personid)
join flug using (flugid)
join flughafen on flug.flughafen_destination=flughafen.flughafenid
where (flughafenid = 'Palma de Mallorca') xor (flughafenid = 'Barcelona')
;
但这会引发以下错误:
An error occurred when executing the SQL command: select * from person join passagierliste using (personid) join flug using (flugid) join flughafen on flug.flughafen_... ORA-00933: SQL command not properly ended [SQL State=42000, DB Errorcode=933]
Execution time: 0.03s
1 statement(s) failed.
更新
发现错误但不是错误(我应该使用 bezeichnung 而不是 flughafenid:
select *
from person
join passagierliste using (personid)
join flug using (flugid)
join flughafen on flug.flughafen_destination=flughafen.flughafenid
where (bezeichnung = 'Palma de Mallorca') xor (bezeichnung = 'Barcelona')
;
您可以按 personid 分组并计算组中不同的描述 (bezeichnung)。由于 WHERE
子句,您知道只选择了马略卡岛或巴塞罗那的描述。这意味着如果每个人有超过 1 个不同的描述,那么他们都访问过。将此(未经测试)用作 CTE 或子查询以从 person
table.
select person.personid
from person
join passagierliste using (personid)
join flug using (flugid)
join flughafen on flug.flughafen_destination=flughafen.flughafenid
where bezeichnung IN('Palma de Mallorca', 'Barcelona')
group by person.personid
having count(distinct bezeichnung) = 1