今天接到了一个需求,需要将表数据按照创建时间create_time排序,然后把排序结果赋值给新增字段order_no
sql如下:
新增字段:
alter table product add column order_no int(8) DEFAULT NULL COMMENT '排序';
按照create_time排序赋值给order_no:
set @mycnt = 0; update product set order_no= (@mycnt := @mycnt +1) order by create_time ASC;
可以根据业务需要将update语句改为select语句,新增where条件进行查询等
欢迎技术大佬和java学习者加入扣扣群:344635699