开发者

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜