开发者

Mysql query distinct desc order

开发者 https://www.devze.com 2023-03-19 23:58 出处:网络
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

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

精彩评论

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

关注公众号