列出所有已出版各种类型书籍的作者

时间:2014-07-30 09:21:55

标签: sql oracle

列出已发布所有类型图书的作者的authorid,authorname和amountpayable。

Author表:

Authorid Authorname Amountpayable

Manuscript

Bookid Authorid Bookname Genre Noofcopies Amount 

这是我试过的查询:

select 
    AUTHORID,
    authorname,
    amountpayable 
from author 
Where authorid IN having count(distinct "GENRE") = (select count(distinct "GENRE") from manuscript);

1 个答案:

答案 0 :(得分:0)

你的逻辑(似乎每个作者的不同类型的数量等于不同类型的数量)是正确的。以下查询是否可以获得预期的结果?

修改: 在内联视图中将表名更改为Manuscript。

SELECT a.*
FROM author a
INNER JOIN
(
    SELECT
        authorid,
        COUNT(DISTINCT Genre) num_genres
    from Manuscript
    GROUP BY authorid
) authors_genres
ON a.authorid = authors_genres.authorid
INNER JOIN
(
    SELECT
        COUNT(DISTINCT Genre) num_genres
    FROM Manuscript
) all_genres
ON authors_genres.num_genres = all_genres.num_genres;