有没有办法在Laravel中以单一连接方式运行多个更新查询,
查询:
update users set score = score+130 where id = 12;
update users set score = score+10 where id = 10;
update users set score = score+10 where id = 14;
我试过:(不工作)
DB::update("
update users set score = score+130 where id = 12;
update users set score = score+10 where id = 10;
update users set score = score+10 where id = 14;
");
感谢,
答案 0 :(得分:1)
您的案例可以通过两个查询解决:
DB::table('users')->where('id', 12)->increment('score', 130);
DB::table('users')->whereIn('id', [10, 14])->increment('score', 10);