3

我在 MySQL 方面不是很好,所以需要一些帮助。我有三个表作者 (author_id, name), book (book_id, name), publisher(id, author_id, book_id)

我只想获取那些仅在 rdbms 上撰写/出版书籍的作者。

我试过:

SELECT a.author_id, a.name, b.name as bookname
FROM author a
LEFT JOIN publisher p ON p.author_id = a.author_id
INNER JOIN book b ON b.book_id = p.book_id ANd b.name='rdbms'

这给了我所有写过关于 rdbms 的书的作者以及其他写过一些其他主题的书的作者,所以我想排除他们。

4

1 回答 1

1

试试这个

SELECT a.author_id, a.name, b.name as bookname
FROM author a
LEFT JOIN publisher p ON p.author_id = a.author_id
INNER JOIN book b ON b.book_id = p.book_id
group by a.author_id
HAVING count(p.book_id) = 1 AND bookname='rdbms'
于 2013-01-22T04:50:48.037 回答