本文介绍了通过desc选择不同的价值顺序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想通过s.notime或其他方式选择不同的customer_id顺序

i want to select distinct customer_id order by either s.no or time or anyhow

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

and it is giving the answer as 4 2 3 but as i want it should be 2 3 4

推荐答案

因此,您的问题陈述是您想要customer_id列表,从其最大时间值开始以降序排列",对吗?

So your problem statement is "You want the list of customer_id, sorted in descended order from their largest time value", right?

SELECT customer_id, MAX(time)
FROM table_name
GROUP BY customer_id
ORDER BY MAX(time) DESC

这篇关于通过desc选择不同的价值顺序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-01 11:08