我想customer_id通过s.no或time或以任何方式选择不同的顺序
customer_id
s.no
time
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
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