1

我一直试图将此查询限制为作者不止一位(应该是四位)的书籍,但我无法弄清楚。有人可以帮忙吗?

这是我的代码:

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.

任何帮助将非常感激。

4

1 回答 1

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
于 2013-08-18T05:44:47.427 回答