为什么我无法获得total_time_driven_at_this_trip的描述顺序?
SELECT DISTINCT (`name`),
MAX( `total_time_driven_at_this_trip` ) as trip
FROM `users`
LEFT JOIN `trip_nsws` ON users.id = trip_nsws.user_id
GROUP BY `user_id`
ORDER BY `total_time_driven_at_this_trip` DESC
LIMIT 0 , 30
答案 0 :(得分:2)
结果集中没有用于排序的列total_time_driven_at_this_trip
。
只有DISTINCT(name)
和trip
。
您可能想要ORDER BY trip DESC
。
答案 1 :(得分:2)
因为您将其别名为trip
并使用GROUP BY
SELECT `name`, MAX(`total_time_driven_at_this_trip`) as trip
FROM `users` LEFT JOIN `trip_nsws` ON users.id = trip_nsws.user_id
GROUP BY `user_id`
ORDER BY `trip` DESC
LIMIT 0, 30