我的问题类比是这样的:
table: place
id title branch
===============================
1 pizza store california
2 pizza store manhattan
3 coffee shop california
4 pizza store texas
5 cookie store new york
table: rating
id place_id rating
================================
1 1 3.5
2 2 5.0
3 2 4.2
4 2 5.0
5 5 4.0
我使用查询:
SELECT F.id AS id, F.title AS title, G.rating
FROM place F
JOIN rating G ON F.id = G.place_id
GROUP BY F.title
显示将是:
id title rating
===========================
1 pizza store 3.5
3 coffee shop -
5 cookie store 4.0
我想要的是对评级最高的标题进行排序,在这种情况下,我希望它显示评级为 5 和 id 2 的披萨店。是否可以在 GROUP BY 中插入一些子查询?
提前致谢!!