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中为查询结果集生成行号的方法。通过设置变量并使用更新语句联合子查询的方式,可以有效地为tbl_material_stone表中的记录按stone_id排序后添加行号。
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;
1283
1361
912
1215
1883
1150

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