我想根据num和id列从源表中获取最新记录,并插入到目标表中。场景在所附的屏幕截图中解释。可以使用“最新记录日期”列。截图谢谢。
nxagd54h1#
Select num,id, date FROM ( Select *, ROW_NUMBER() OVER(partition by num,id Order by date desc) as rnk FROM source_table )a WHERE rnk = 1;
flseospp2#
SELECT NUM,ID,DATE FROM TABLE_TEMP QUALIFY RANK OVER(PARTITION BY NUM,ID ORDER BY DATE DESC)=1;
您可以使用单行查询来完成此操作从表\u temp qualify rank over(partition by num,id order by date desc)=1中选择num,id,date;
djmepvbi3#
通过使用相关子查询
select * from your_table t where t.date= ( select max(date) from your_table t1 where t1.num=t.num and t1.id=t.id )
你可以用 max() 功能
max()
select num,id,max(date) from your_table t group by num,id
3条答案
按热度按时间nxagd54h1#
flseospp2#
您可以使用单行查询来完成此操作
从表\u temp qualify rank over(partition by num,id order by date desc)=1中选择num,id,date;
djmepvbi3#
通过使用相关子查询
你可以用
max()
功能