列出已发布所有类型图书的作者的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);
答案 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;