ISQL对于每个作者,列出他们的编号,姓氏和书籍数量

时间:2013-04-19 22:40:13

标签: mysql

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张桌子;书,作者和写作。我需要找到作者写过多少本书。我需要子查询吗?

1 个答案:

答案 0 :(得分: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;

虽然我觉得你的专栏名称不是很正确