除了使用group_concat,還有其他方法可以實作類似的代碼嗎?
set ids = (select GROUP_CONCAT(`id`) from `table` where flag=0);
insert into `table` select * from table where id in(ids);
update `table` set flag=1 where id in(ids);
uj5u.com熱心網友回復:
=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]);
uj5u.com熱心網友回復:
這個存盤程序有可能并發呼叫,這樣的話應該會出現重復insert的情況。
for update應該也不行,select ... for update 到update執行時間,如果有新的記錄,這些新記錄沒有insert就設flag=1了。
uj5u.com熱心網友回復:
放在事務就可以了start transaction;
insrt ....
update ...
commit;
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/105113.html
標籤:MySQL
下一篇:mongoimport 無法匯入
