2012-06-14 102 views
0

我有兩個表:翻譯SQL查詢學說2

author (id, first_name, last_name) 
books (id, title, rate, author_id) 

,我需要得到與收視率最高的書(每一個作者)的作者。

在SQL:

SELECT a.*, highest_rated_book.* 
     FROM authors a 
     LEFT JOIN (SELECT * FROM books b ORDER BY b.rate DESC) AS highest_rated_book 
     ON a.id = highest_rated_book.author_id 
     GROUP BY highest_rated_book.author_id 
     ORDER BY a.id; 

但我需要這個教義2.我有最大的問題是左合併連接和子查詢。

這可能嗎?

回答