Mysql query distinct desc order
Why can I not get Desc order for total_time_driven_at_this_trip?
SELECT DISTINCT (`name`),
MAX( `total_time_driven_at_th开发者_如何学Pythonis_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
Cause you aliased it as trip and are using 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
There is no column total_time_driven_at_this_trip in your result set to use for ordering.
There is only DISTINCT(name) and trip.
You probably want to ORDER BY trip DESC.
加载中,请稍侯......
精彩评论