简体   繁体   English

Mysql 查询不同的 desc 顺序

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM