求一条SQL update语句
有以下数据:
srn groupcode Field30
h30511 *20111207000079* LK169849491CN
h30510 *20111207000079* NULL
u70377 *20111207000116* NULL
u70374 *20111207000116* NULL
u70375 *20111207000116* LK168318165CN
u70376 *20111207000116* NULL
把groupcode相同的对应的Field30列进行更新,要得到以下结果:
srn groupcode Field30
h30511 *20111207000079* LK169849491CN
h30510 *20111207000079* LK169849491CN
u70377 *20111207000116* LK168318165CN
u70374 *20111207000116* LK168318165CN
u70375 *20111207000116* LK168318165CN
u70376 *20111207000116* LK168318165CN
.....
.....
------解决方案--------------------
SQL code
update
a
set
field30=b.field30
from
tb a,
(select groupcode,max([Field30]) from tb group by groupcode)b
where
a.groupcode=b.groupcode
------解决方案--------------------
SQL code
update a set [Field30]=(select max([Field30]) from tb where groupcode=a.groupcode) from tb a