我一直试图将此查询限制为具有多个作者的书籍(应该是四个),但我无法弄明白。有人可以帮忙吗?
这是我的代码:
SELECT title, COUNT(authorid) AS "Number of Authors"
FROM book_author, books, publisher
WHERE publisher.pubid(+) = books.pubid
AND books.bookid(+) = book_author.bookid
GROUP BY title;
结果如下:
SQL> SELECT title, COUNT(authorid) AS "Number of Authors"
2 FROM book_author, books, publisher
3 WHERE publisher.pubid(+) = books.pubid
4 AND books.bookid(+) = book_author.bookid
5 GROUP BY title;
TITLE Number of Authors
------------------------------ -----------------
DATABASE IMPLEMENTATION 3
PAINLESS CHILD-REARING 3
HOW TO GET FASTER PIZZA 1
SHORTEST POEMS 1
BIG BEAR AND LITTLE DOVE 1
BODYBUILD IN 10 MINUTES A DAY 2
HOLY GRAIL OF ORACLE 1
HANDCRANKED COMPUTERS 2
HOW TO MANAGE THE MANAGER 1
COOKING WITH MUSHROOMS 1
BUILDING A CAR WITH TOOTHPICKS 1
E-BUSINESS THE EASY WAY 1
REVENGE OF MICKEY 1
THE WOK WAY TO COOK 1
14 rows selected.
非常感谢任何帮助。
答案 0 :(得分:1)
HAVING
子句将过滤聚合值:
SELECT title, COUNT(authorid) AS "Number of Authors"
FROM book_author, books, publisher
WHERE publisher.pubid(+) = books.pubid
AND books.bookid(+) = book_author.bookid
GROUP BY title
HAVING COUNT(authorid) > 1