我正在尝试按日期对结果进行分组,但是同一时间想要显示时间戳。我有一张如下表......
DateTme col1 col2 col3 col4
12/16/2014 3:23 we 23 xyz R
12/16/2014 5:14 re 45 uty X
12/16/2014 5:15 re 45 uty X
12/16/2014 5:47 ue 87 owu B
12/16/2014 6:30 oe 92 pqr M
12/16/2014 6:33 oe 92 pqr M
我应该得到结果......
DateTme col1 col2 col3 col4
12/16/2014 3:23 we 23 xyz R
12/16/2014 5:15 re 45 uty X
12/16/2014 5:47 ue 87 owu B
12/16/2014 6:33 oe 92 pqr M
如果我按日期分组,col1,col2,col3 col4我得到重复,因为时间以秒为单位不同。我不能将First_Value与PARTITION一起使用,因为没有唯一ID,所有4列都有唯一性。请让我知道如何实现这一目标。谢谢。
答案 0 :(得分:1)
试试这个:
select datetme,col1,col2,col3,col4 from (
select t1.*,row_number() over (partition by trunc(datetme),col1,col2,col3,col4
order by datetme desc) cont from your_table t1)
where cont = 1
order by datetme
trunc(datetme)
分区解决时间问题。