5条回答 默认 最新
- 张大教主 2018-02-11 03:23关注
我理解你的意思是相同txtShopCode值的记录要按照从1递增更新sort字段值? 如果这样的话,也简单,但是为了方便更新执行,需要增加一个辅助更新字段,名称:num,更新后可删除该字段 假定你的表名为 tname alter table tname add num INT NOT NULL AUTO_INCREMENT;----增加递增字段 update tname set sort=1 where 1=1;----先将所有sort字段赋初始值1; update tname m inner join (select a.txtGuid guid, (select count(*) from tname where num<=a.num and txtShopCode=a.txtShopCode) sortValue from tname a) n on m.txtGuid=n.guid set m.sort=n.sortValue; alert table tname drop column num;----删除新增字段num
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报