sql 語句階段性總結 多表聯合更新

2021-08-16 21:18:57 字數 3040 閱讀 3979

(1)根據支行**更新支行名稱,新建表temp_sub_branch 將需要更新的資料匯入,執行sql

update online_bra_off_rec_sub_bra a

set a.sub_branch_name=(

select b.sub_branch_name

from temp_sub_branch b

where b.sub_branch_org_code=a.sub_branch_org_code)

where exists (

select 1

from temp_sub_branch b

where b.sub_branch_org_code=a.sub_branch_org_code)

(2)根據支行名稱更新支行**,新建表temp_sub_branch_2 將需要更新的資料匯入,執行sql

update online_bra_off_rec_sub_bra a

set a.sub_branch_org_code=(

select b.sub_branch_org_code

from temp_sub_branch_2 b

where b.sub_branch_name=a.sub_branch_name)

where exists (

select 1

from temp_sub_branch_2 b

where b.sub_branch_name=a.sub_branch_name)

(3)新建表temp_all,將全量資料匯入,執行sql,將支行表中的線上推廣碼、線下推廣碼填充上

update online_bra_off_rec_sub_bra a

set a.online_promotion_code=(

select b.online_promotion_code from temp_all b

where b.sub_brach_org_code=a.sub_branch_org_code)

where (a.online_promotion_code is null) and exists (select 1 from temp_all b

where b.sub_brach_org_code=a.sub_branch_org_code)

同理更新線下推廣碼

update online_bra_off_rec_sub_bra a

set a.offline_promotion_code=(select b.offline_promotion_code from temp_all b

where b.sub_brach_org_code=a.sub_branch_org_code)

where exists (select 1 from temp_all b

where b.sub_brach_org_code=a.sub_branch_org_code)

(4)更新temp_all表,填充branch_id 和parent_branch_id的值,執行sql

update temp_all a

set a.branch_id=(select b.id from online_bra_off_rec_bra b where b.branch_name=a.branch_name)

where exists (select 1 from online_bra_off_rec_bra b where b.branch_name=a.branch_name)

同理更新和parent_branch_id的值,執行sql

update temp_all a

set a.parent_branch_id=(

select

b.id

from online_bra_off_rec_parent_bra b

where b.parent_branch_name=a.parent_branch_name)

where exists (

select 1

from online_bra_off_rec_parent_bra b

where b.parent_branch_name=a.parent_branch_name)

(5)根據temp_all表更新二級分行表online_bra_off_rec_bra的parent_branch_id,執行sql

update online_bra_off_rec_bra a

set a.parent_branch_id=(select distinct b.parent_branch_id from temp_all b

where b.branch_name=a.branch_name)

where exists (select 1 from temp_all b where b.branch_name=a.branch_name)

(6)根據temp_all表更新支行表online_bra_off_rec_sub_bra的branch_id,執行sql

update online_bra_off_rec_sub_bra aset a.branch_id=(select distinct b.branch_id from temp_all bwhere b.sub_branch_org_code=a.sub_branch_org_code)where exists (select  1 from temp_all b where b.sub_branch_org_code=a.sub_branch_org_code)
(8)驗證資料

select * from online_bra_off_rec_sub_bra t

where online_promotion_code is null or offline_promotion_code is not null

階段性總結

今天聽學長交流了一些人生的經驗,便有了一些感觸,加上對自己最近的學習狀態的總結,就寫一篇部落格給自己一點指示。最近渾渾噩噩的,有幾次考試也沒考好,考後也沒總結。晚自習本想刷一些題,複習一下,或是學習一點技術。看見其他同學在打擺,便動搖了。最後心中也只是徒留深深的罪惡感。所以我也是時候對自己的未來進行...

階段性總結

感覺上個星期還挺痛苦的,因為要練演算法,每個人都告訴我說演算法很重要很重要,但是演算法對我來說就像是一根很亂的神經,一觸就炸了,可我的驕傲還不允許我放棄。在leetcode上練習的時候是直接告訴用什麼方法,在寫藍橋杯演算法的時候就像是閱讀理解,經常讀不懂是什麼意思,要不就是理解錯誤,追根究底還是做的...

自考階段性總結

週六日這兩天的自學考試就這樣隨著落日再是告一段落,這是自己經歷的第三次自考。就著這一步走來的歷程著實令人緊張而又亢奮的,一次次的考試,乙個個課程的考試,讓我們朝著自考畢業證更進一步。總體而言,自學考試的經歷實在難稱完美。頓時轉折自己的學習需要不斷總結,需要針對這一屆的學習方法來個總結,思考這樣的學習...