我在最後一個「高級選擇語句」的問題,並不能得到正確的答案。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