gpt4 book ai didi

php - Mysql查询distinct desc顺序

转载 作者:太空宇宙 更新时间:2023-11-03 11:13:49 25 4
gpt4 key购买 nike

为什么我无法获得 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

最佳答案

因为您将其别名为 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

关于php - Mysql查询distinct desc顺序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6687774/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com