我在最后一个“高级选择语句”的问题,并不能得到正确的答案。SQL Aggregate Count语句
表1:书虫数据库的模式。主键带下划线。有一些外键引用将表连接在一起;你可以使用这些与自然连接。
Author(aid, alastname, afirstname, acountry, aborn, adied).
Book(bid, btitle, pid, bdate, bpages, bprice).
City(cid, cname, cstate, ccountry).
Publisher(pid, pname).
Author_Book(aid, bid).
Publisher_City(pid, cid).
问题是......“找到写过三本或更多本书的作者的名字。”
代码工作,但我想要的所有作者名称,而不是作者的ID ..
select count(aid) as authorBook, aid as authorName
from Author_book natural join Author
group by aid
having count(aid) > 3;
决赛桌出来作为...
authorbook | authorname
------------+------------
8 | dick
4 | thar
(2 rows)
您的查询中需要作者和书籍表。加入或子选择! – jarlh 2015-02-24 16:22:46