gpt4 book ai didi

sql - 使用带 (+) 运算符的传统连接子句

转载 作者:行者123 更新时间:2023-12-01 23:17:11 25 4
gpt4 key购买 nike

我真的被来自 JustLee 数据库的 SQL 问题困住了。不想找任何人做我的作业,但不幸的是我被困住了......

Questions: Show all authors and books they have written. Include authors that haven't finished writing their books yet. Include author last name, author first name, isbn, and book title. Use traditional join clause with the (+) operator.

我最好的猜测是:

select lname, fname, isbn, title
from author a, bookauthor ba, books b
where a.authorid(+) = ba.authorid
and ba.isbn(+) = b.isbn
order by 1,2,3,4;

但是我得到一个列定义不明确的错误。任何帮助将非常感激。谢谢!

最佳答案

您需要在 SELECT 列表中限定不明确的列名:

select lname, fname, b.isbn, title
from author a, bookauthor ba, books b
where a.authorid(+) = ba.authorid
and ba.isbn(+) = b.isbn
order by 1,2,3,4;

如果没有别的,最好在 select 中限定所有列,以明确该列来自哪个表。我还建议您切换到现代 JOIN 语法,并在 ORDER 子句中明确列出列:

select a.lname, a.fname, b.isbn, b.title
from author a
LEFT JOIN bookauthor ba
ON a.authorid = ba.authorid
LEFT JOIN books b
and ba.isbn = b.isbn
order by a.lname, a.fname, b.isbn, b.title;

关于sql - 使用带 (+) 运算符的传统连接子句,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41928707/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com