你這個報錯,說白了就是當(dāng)a.值1等于b.值1的時候,查出來的值2有多個結(jié)果,數(shù)據(jù)庫直接懵了,不知道該用哪個更新。
如果邏輯不復(fù)雜的話,可以這么寫:
update tab1 a set 值2 = (select min(值2) from tab2 b where a.值1 = b.值1)
where exists (select 1 from tab2 b where a.值1 = b.值1)
and a.值1 in (select 值1 from tab2)
and cop_g_no in (select * from tab3)
這里用了min(值2),你也可以用max,看具體想取啥。要是規(guī)則更復(fù)雜就得另說啦~
如果邏輯不復(fù)雜的話,可以這么寫:
update tab1 a set 值2 = (select min(值2) from tab2 b where a.值1 = b.值1)
where exists (select 1 from tab2 b where a.值1 = b.值1)
and a.值1 in (select 值1 from tab2)
and cop_g_no in (select * from tab3)
這里用了min(值2),你也可以用max,看具體想取啥。要是規(guī)則更復(fù)雜就得另說啦~