我想通过 s.no
或 time
或任何方式选择不同的 customer_id
订单
s.no customer_id time
1 3 100001
2 2 100002
3 4 100003
4 3 100004
5 2 100005
我正在使用
select distinct(customer_id) from table_name order by time DESC
它给出的答案是 4 2 3
但我希望它应该是 2 3 4
最佳答案
所以你的问题陈述是“你想要 customer_id 的列表,从它们的最大时间值降序排列”,对吧?
SELECT customer_id, MAX(time)
FROM table_name
GROUP BY customer_id
ORDER BY MAX(time) DESC
关于mysql - 按 desc 选择不同的值顺序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19334128/