sql批量刷数据

应用场景

== 新增了一个字段,老数据的该字段都为空,值需要从其他表里去取 ==

解决方法

update gd_lzxx_bztjbb_zb zb
   set gdstatus = '4',
       gdbjr    = (select a.create_by
                     from (select gdid, create_by, create_time
                             from gd_operation_step
                            where create_time >=
                                  to_date('2023-04-20',
                                          'yyyy-MM-dd HH24:mi:ss')
                              and create_time <=
                                  to_date('2023-05-01',
                                          'yyyy-MM-dd HH24:mi:ss')
                              and (remark like '%在受理阶段决定办结%' or
                                  remark like '%在受理阶段自动办结%' or
                                  remark like '%在受理阶段转12345办结%')) a
                     left join gd_lzxx_bztjbb_zb b on a.gdid = b.gdid
                    where b.GDSTATUS is null
                      and zb.gdid = b.gdid),
       gdbjsj   = (select a.create_time
                     from (select gdid, create_by, create_time
                             from gd_operation_step
                            where create_time >=
                                  to_date('2023-04-20',
                                          'yyyy-MM-dd HH24:mi:ss')
                              and create_time <=
                                  to_date('2023-05-01',
                                          'yyyy-MM-dd HH24:mi:ss')
                              and (remark like '%在受理阶段决定办结%' or
                                  remark like '%在受理阶段自动办结%' or
                                  remark like '%在受理阶段转12345办结%')) a
                     left join gd_lzxx_bztjbb_zb b on a.gdid = b.gdid
                    where b.GDSTATUS is null
                      and zb.gdid = b.gdid)
 where gdid in (select b.gdid
                  from (select gdid, create_by, create_time
                          from gd_operation_step
                         where create_time >=
                               to_date('2023-04-20', 'yyyy-MM-dd HH24:mi:ss')
                           and create_time <=
                               to_date('2023-05-01', 'yyyy-MM-dd HH24:mi:ss')
                           and (remark like '%在受理阶段决定办结%' or
                               remark like '%在受理阶段自动办结%' or
                               remark like '%在受理阶段转12345办结%')) a
                  left join gd_lzxx_bztjbb_zb b on a.gdid = b.gdid
                 where b.GDSTATUS is null)
   and GDSTATUS is null

update gd_wxb a
   set ja_time = (select create_time
                    from (select create_time
                            from gd_wxb_operation_step
                           where gdid = a.id
                           order by create_time desc)
                   where rownum = 1)
 where id in (select id
                from gd_wxb
               where status = '2'
                 and del_flag = 0)

你可能感兴趣的:(sql,数据库)