MERGE INTO uf_jjrapxx t
USING (
       
       WITH
paixu as (
SELECT lx,rq, ROW_NUMBER() OVER (ORDER BY id) AS id FROM uf_jjrapxx  ORDER BY rq

),
tmp1 AS (
SELECT id,rq, ROW_NUMBER() OVER (ORDER BY id) AS gzrxh FROM paixu WHERE lx=0
),

tmp2 AS (
SELECT a.id,a.rq,      LEVEL  AS det FROM paixu a  START WITH a.lx=0 OR a.id = 1  CONNECT BY PRIOR a.id=a.id-1 AND a.lx!=0 ORDER BY rq

)
SELECT a.id,a.rq, CASE WHEN a.id = 1 THEN 0 ELSE b.gzrxh END AS gzrxh FROM tmp2 a LEFT JOIN tmp1 b ON a.id-a.det+1=b.id
) s
ON (t.id = s.id)
WHEN MATCHED THEN
UPDATE SET t.gzrxh = s.gzrxh




