这是我的查询:
select p1.driver_id, p1.name, o1.driver_id, o1.license, part.license, part.amount
from
(person p1 full outer join owns o1 on p1.driver_id = o1.driver_id) and
(Participated part full outer join ol on part.license = o1.license)
我得到的sql语句未正确结束错误。我只想构建表格,作为解决更复杂问题的过程的一部分。
答案 0 :(得分:1)
这不是您在FROM
部分中定义关系的方式。请尝试以下方法:
select p1.driver_id, p1.name, o1.driver_id, o1.license, part.license, part.amount
from
person p1
full outer join owns o1 on p1.driver_id = o1.driver_id
full outer join Participated part on part.license = o1.license;
注意:
FROM
之后,您可以列出一些关系(逗号分隔),并且在您正确编写时,关系也可以是a FULL OUTER JOIN b ON ...
形式。您也可以将这些(如果您愿意,使用括号)链接为
a FULL OUTER JOIN b ON ... FULL OUTER JOIN c ON ...
AND
来连接关系,该关系仅用于连接条件。您可以括起语句以形成子查询,例如
(SELECT * FROM a FULL OUTER JOIN b ON ...) AS t
但请注意,您需要在开头将SELECT *
转换为关系,并且在大多数系统中,您需要在(示例中为t
)之后使用别名。
答案 1 :(得分:0)
SELECT p1.driver_id, p1.name, o1.driver_id, o1.license, part.license, part.amount
FROM person p1
FULL OUTER JOIN owns o1
ON p1.driver_id = o1.driver_id
FULL OUTER JOIN Participated part
ON part.license = o1.license