时间:2021-07-01 10:21:17 帮助过:13人阅读
将分组记录中的第一条数据的某个字段更新到第二条数据上的字段;
--把序号为2的结束时间 更新为 序号为1的开始时间 WITH t2 as ( SELECT * FROM( SELECT ROW_NUMBER() OVER ( partition by C_BH_ZFXX ORDER BY DT_KSSJ DESC) as num , C_BH_ZFXX, DT_KSSJ, DT_JSSJ, C_BH FROM DB_JY..T_FJFY_FJJL WHERE --c_bh_zfxx in( ‘046B7C4311C0413FBD8A5B5EDC5C9460‘,‘087CE841726B43209439B09E87AE8C48‘) AND DT_JSSJ is NULL )b WHERE b.num=2 ) UPDATE t2 SET t2.dt_jssj = t1.dt_kssj FROM( SELECT * FROM( SELECT ROW_NUMBER() OVER ( partition by C_BH_ZFXX ORDER BY DT_KSSJ DESC) as num , C_BH_ZFXX, DT_KSSJ, DT_JSSJ, C_BH FROM DB_JY..T_FJFY_FJJL WHERE -- c_bh_zfxx in( ‘046B7C4311C0413FBD8A5B5EDC5C9460‘,‘087CE841726B43209439B09E87AE8C48‘) AND DT_JSSJ is NULL ) a WHERE a.num = 1 ) t1 WHERE t1.C_BH_ZFXX = t2.C_BH_ZFXX
sqlserver数据库中sql的使用
标签:over font row esc sql 时间 第一条 weight 数据