在一個資料庫中,有11張表(t1...t11),11張表都存在三個相同的欄位a,b,現在想根據a和b兩個欄位的值t.a=x and t.b like%y%,去select 11張表中所有符合條件的資料,然后update set t.a=z where 接以上查詢資料。
select t1.a from t1 where t1.a=x and t1.b like%y%, 然后update set t1.a=z;
初步想法是搞一個回圈更新,但是sql不支持陣列,集合又不合適。t.a(x)、t.b(y)、t.a(z)的取值都是一個集合,都是6000個,簡單來說就是根據 t.a和t.b的條件查詢所有表的t.a,然后更新t.a
有什么好的解決辦法嗎? 單表資料在2萬行左右。
uj5u.com熱心網友回復:
可以把 這11個表的相關的幾個相同欄位 及主鍵合并到一個表中uj5u.com熱心網友回復:
merge into t using(
select a,b,z from t1 where a...and b...
union all
select a,b,z from t2 where a... and b...
...
union all
select a,b,z from t11 where a... and b...
) u
on (t.a=u.a and t.b=u.b)
when matched then
update set t.a=u.z;
大概就這思路吧。
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/13083.html
標籤:高級技術
