Friday, 15 June 2012

mysql - How to update a sql table column with a new value computed by SQL function? -



mysql - How to update a sql table column with a new value computed by SQL function? -

i have 1 table table cols , b , next values

a b 1 0 1 0 2 0 2 0 3 0 4 0

i want update column b function thefunc(a) taking col argument. there many rows, hence takes long time if utilize query

update table set b = thefunc(a)

i believe if compute values each unique col value map these related rows , faster instead of computation each row. how can in sql?

update tab t1 set t1.b = (select t2.c (select thefunc(a) c tab grouping a) t2 t2.c = t1.a);

mysql sql

No comments:

Post a Comment