为提高效率,提问时请提供以下信息,问题描述清晰可优先响应。
【DM版本】:7
【操作系统】:linux
【CPU】:
【问题描述】*:
我需要在一个已经分组的结果集中,对某个字段进行排序后筛选取值,但是实现不出来。
样例如下:
select
t1.xxx_id,
【此处需要对t1表的另外一个字段t1.statistic_time进行排序取得最大值的一行记录后取出t1表的第三个不同字段t1.lenght进行使用】
from
table1 t1
group by t1.xxx_id
不知道大佬们能不能看得明白我的意思
或者试一下分组函数呢?
我理解的你的需求就是,按照每个city_id分组,取每个分组内statistic_time最大的那条记录。
select id,city_id,value_A,value_B,value_C,statistic_time
from (
select a.id,a.city_id,
a.value_A,
a.value_B,
a.value_C,
a.statistic_time,
row_number() over(partition by a.city_id order by a.statistic_time desc) as f_part
from TB1 a)
where f_part = 1;
你参考下,如果我理解的不对或者不能实现你的需求我们再交流。
能举个例子吗,没理解你的意思 qaq