比如
name num
a
a
b
b
c
开始时num是空的,利用count语句更新成如下样式.按name出现次数给num赋值
name num
a 2
a 2
b 2
b 2
c 1
------解决方案--------------------
update a
set num=b.num
from tb a
inner join (select name,count(*) as num from tb group by name) b
on a.name=b.name
------解决方案--------------------
咱也凑个热闹:
update a003
set num=(select COUNT(1) from a003 b where a.name=b.name)
from a003 a
------解决方案--------------------
或者更简化一点:
update a003
set num=(select COUNT(1) from a003 b where a003.name=b.name)