Home > database >  Mysql stored procedure how to achieve similar functionality
Mysql stored procedure how to achieve similar functionality

Time:10-02

In addition to using group_concat, are there any other method can achieve similar code?
 
The set ids=(select GROUP_CONCAT (` id `) from ` table ` where flag=0).
Insert into ` table ` select * from table where id in (ids);
The update ` table ` set flag=1 where id in (ids);

CodePudding user response:

=SQL] insert into ` table ` select * from table where id in (select id from ` table ` where flag=0).
Update ` table ` set flag=1 where id in (select id from ` table ` where flag=0 [code [/code]);

CodePudding user response:

reference 1st floor ZJCXC response:
=SQL] insert into ` table ` select *, 1 from the table where id in (select id from ` table ` where flag=0).
Update ` table ` set flag=1 where id in (select id from ` table ` where flag=0 [code [/code]);


The stored procedure may be concurrent calls, so should appear to repeat the insert,

For update should also not line, the select... For update to update the execution time, if there is a new record, the new record set a flag=1 without insert,

CodePudding user response:

In the affairs can
Start the transaction;
Insrt...
The update...
commit;

  • Related