[英]Mysql query distinct desc order
Why can I not get Desc order for total_time_driven_at_this_trip?为什么我无法获得 total_time_driven_at_this_trip 的 Desc 订单?
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
There is no column total_time_driven_at_this_trip
in your result set to use for ordering.结果集中没有列
total_time_driven_at_this_trip
可用于排序。
There is only DISTINCT(name)
and trip
.只有
DISTINCT(name)
和trip
。
You probably want to ORDER BY trip DESC
.您可能想要
ORDER BY trip DESC
。
Cause you aliased it as trip
and are using GROUP BY
因为您将其别名为
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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.