我有一个表格,其中包含cols A和B以及以下值
A B
1 0
1 0
2 0
2 0
3 0
4 0
我想用函数theFunc(A)
更新列B,将col A作为参数。有很多行,因此如果我使用像
更新表 SET B = theFunc(A)
我相信如果我计算每个唯一col A值的所有值,然后将这些值映射到相关行,它将更快而不是每行的计算。我怎么能在SQL中做到这一点?
答案 0 :(得分:0)
update tab t1 set t1.B = (select t2.C from (select theFunc(A) C from tab group by A) t2 where t2.C = t1.A);