In MySQL, you can do this using the update
/join
syntax:
update table t join
(select grp, max(val) as maxval
from table t
group by grp
) tmax
on t.grp = tmax.grp and t.val = tmax.maxval
set t.chk = 1;
Frage
ID GRP VAL CHK
--- ----- ----- ----
1 1 1 0
2 1 3 0
3 2 7 0
4 2 2 0
5 2 1 0
6 3 5 0
I want to set my CHK field to '1' having maximum value VAL for every group of GRP, so ID 2,3,6 should be set. I don't write my trials here, all seems rubbish :)
Lösung
In MySQL, you can do this using the update
/join
syntax:
update table t join
(select grp, max(val) as maxval
from table t
group by grp
) tmax
on t.grp = tmax.grp and t.val = tmax.maxval
set t.chk = 1;