您好,登錄后才能下訂單哦!
A表(tb_abc):
A | B | |
1 | aa | 0200 |
2 | bb | 0300 |
3 | cc | 0500 |
4 | dd | 1800 |
5 | ee | 2200 |
6 | ff | 3300 |
B表(tb_abcc):
A | B | |
1 | aa | (0201) |
2 | aa | (0202) |
3 | bb | (0301) |
4 | bb | (0302) |
5 | bb | (0303) |
6 | cc | (0501) |
括號里是預期值
規則: 通過B表的a字段匹配A表的a字段,并讀取A表的b字段,按照該值依次增數寫入B表b字段
實現:
update tb_abcc c set c.b = (select tmp.str from (select b.rowid rd, b.a, substr(a.b, 1, 2) || lpad( ( rank () over (partition by b.a order by b.rowid) ), 2, 0 ) str from tb_abc a, tb_abcc b where a.a = b.a) tmp where c.rowid = tmp.rd) where exists (select 'x' from (select b.rowid rd, b.a, substr(a.b, 1, 2) || lpad( ( rank () over (partition by b.a order by b.rowid) ), 2, 0 ) str from tb_abc a, tb_abcc b where a.a = b.a) tmp where c.rowid = tmp.rd);
6 rows updated
select * from tb_abcc;
A B
---- ------
aa 0201
aa 0202
bb 0301
bb 0302
bb 0303
cc 0501
6 rows selected
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。