oracle 中从一个历史表中查询最新日期数据插入到另一个表中语句

先从历史表中查询最新的一个语句:

 select  t.id
   from (
        select r.*, row_number() over(partition by r.分组字段 order by r.排序时间 desc) rw  
        from 表A r 
        where r.del_flag='0'
        ) t  
   where t.rw = 1

下面是完整语句:需要插入的表中字段要和下面查询语句字段对应上

insert into uav_flight_real_location (ID,LOCATION_TIME,GPS_LONGITUDE) 

select  sys_guid() as id,t.time as LOCATION_TIME, t.longitude as GPS_LONGITUDEfrom 表 twhere t.符合条件字段 in(
 select  t.id
   from (
        select r.*, row_number() over(partition by r.分组字段 order by r.排序时间 desc) rw  
        from 表A r 
        where r.del_flag='0'
        ) t  
   where t.rw = 1

猜你喜欢

转载自www.cnblogs.com/xl1314666/p/11980826.html
今日推荐