很多时候我们需要修改某个字段自加。根据某个条件!如案例
phpzy.com 是表
id aid title
1 1 a
2 1 a
3 1 b
4 1 b
5 1 b
修改成
id aid title
1 1 a
2 2 a
3 1 b
4 2 b
5 3 b
update phpzy.com x ,(
select id, (select count(*) from 表a where title= t.title and id<=t.id) as cnt
from phpzy.com t) y
set x.aid=y.cnt
where x.id=y.id
当title不同时
aid重1开始递增
如果一条语句不行可以写成
where title='a'和where title='b'两条实现也行