这是我的SQL
SELECT DISTINCT(scl_reviews.locid),avg(scl_reviews.rating)
AS average,scl_locations.name,scl_locations.phone,scl_locations.address,
scl_location.city,scl_locations.state,scl_locations.zip
FROM scl_reviews
LEFT JOIN scl_locations ON scl_locations.locid = scl_reviews.locid
GROUP BY scl_reviews.locid ORDER BY average DESC LIMIT 100
这意味着它将使用locations
获取highest rating
并按平均值排序。
问题在于,平均为5的记录似乎以不同的方式查询其位置。 有时我的ID为3115的记录是位置1,有时是位置3。
不太清楚最新情况。我认为这与我的查询有关。
答案 0 :(得分:0)
ORDER BY average DESC
无法确定订单的顺序。因此,只需在排序顺序中列出唯一列。您可能希望列号快捷:
ORDER BY 2 DESC, 1 DESC
答案 1 :(得分:0)
添加二级订单。当您的第一个订单具有相同的价值时,这就开始了。 检查新订单条款:
SELECT DISTINCT(scl_reviews.locid),avg(scl_reviews.rating)
AS average,scl_locations.name,scl_locations.phone,scl_locations.address,
scl_location.city,scl_locations.state,scl_locations.zip
FROM scl_reviews
LEFT JOIN scl_locations ON scl_locations.locid = scl_reviews.locid
GROUP BY scl_reviews.locid
ORDER BY average DESC, scl_reviews.locid DESC LIMIT 100