我有两张桌子:
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;
但我在 Doctrine 2 中需要这个。我遇到的最大问题是结合左连接和子选择。
这可能吗?