指尖上的记忆指尖上的记忆
首页
  • 基础
  • Laravel框架
  • Symfony框架
  • 基础
  • Gin框架
  • 基础
  • Spring框架
  • 命令
  • Nginx
  • Ai
  • Deploy
  • Docker
  • K8s
  • Micro
  • RabbitMQ
  • Mysql
  • PostgreSsql
  • Redis
  • MongoDb
  • Html
  • Js
  • 前端
  • 后端
  • Git
  • 知识扫盲
  • Golang
🌟 gitHub
首页
  • 基础
  • Laravel框架
  • Symfony框架
  • 基础
  • Gin框架
  • 基础
  • Spring框架
  • 命令
  • Nginx
  • Ai
  • Deploy
  • Docker
  • K8s
  • Micro
  • RabbitMQ
  • Mysql
  • PostgreSsql
  • Redis
  • MongoDb
  • Html
  • Js
  • 前端
  • 后端
  • Git
  • 知识扫盲
  • Golang
🌟 gitHub

目前遇到这样的需求,需要将如下结构的数据进行更行操作:

iduser_idnono_modifycreated_at
11122021-08-26 08:23:46
21132021-08-26 08:23:50
31142021-08-26 08:23:55

更新为:

iduser_idnono_modifycreated_at
11122021-08-26 08:23:46
2113122021-08-26 08:23:50
3114132021-08-26 08:23:55

通过存储过程循环指定用户,然后进行更新操作,语句如下:

CREATE DEFINER=`qinhong`@`%` PROCEDURE `data_proc`()
BEGIN
	#Routine body goes here...
         declare stop_flag int default 0;
         declare account_id int default 0;
         declare account_user_id int default 0;
         declare num int default 0;

         declare cur1 cursor for select id, user_id, no from update_test where user_id in (select user_id from update_test) order by created_at asc;

         declare continue handler for not found set stop_flag=1;

start transaction;

         open cur1;
         fetch cur1 into account_id,account_user_id,num;
         while stop_flag<>1 DO

           update update_test set no_modify = num where user_id = account_user_id and id = (account_id + 1);

         fetch cur1 into account_id,account_user_id,num;
         end while;
         close cur1;
commit;

END
--返回--