mysql产生行号:
set @n = 0;
update tbl_material_stone a, (select stone_id,@n:=@n+1 r from tbl_material_stone order by stone_id) b set no = r where a.stone_id =b.stone_id;
本文介绍了一种在MySQL中为查询结果集生成行号的方法。通过使用变量和更新语句结合子查询,可以有效地为每个返回的记录分配一个唯一的行号。此方法适用于需要对查询结果进行编号的场景。
mysql产生行号:
set @n = 0;
update tbl_material_stone a, (select stone_id,@n:=@n+1 r from tbl_material_stone order by stone_id) b set no = r where a.stone_id =b.stone_id;
1481
1075
5274
625
3075
1935

被折叠的 条评论
为什么被折叠?