0
SELECT a.author_num, a.author_last, COUNT(w.book_code)
FROM book.book b, book.author a, book.wrote w
WHERE (b.book_code=w.book_code and w.author_num=a.author_num)
ORDER BY a.author_last DESC;

我有 3 张桌子;书、作者和写作。我需要找出作者写了多少本书。我需要子查询吗?

4

1 回答 1

0

你可以只使用一个GROUP BY

SELECT a.author_num, a.author_last, COUNT(w.book_code)
FROM book.book b, book.author a, book.wrote w
WHERE (b.book_code=w.book_code and w.author_num=a.author_num)
GROUP BY a.author_num, a.author_last
ORDER BY a.author_last DESC;

虽然我觉得你的列名不太正确

于 2013-04-19T22:47:03.970 回答