问答 / 0 / 2 / 创建于 3年前 / 更新于 3年前
我想限制更新100条,尝试直接加上limit报错
UPDATE `cy_customer` INNER JOIN `cy_customer_group_details` ON `cy_customer`.`id` = `cy_customer_group_details`.`customer_id` SET `cy_customer`.`ascription` = '3' WHERE `customer_group_id` = '5'
mysql 支持这样限制更新记录条数
update tableName set updated_at = ‘2021-8-23 13:01:00' limit 10
试试子查询中查出id,再更新,类似下面这样:
update xx set xx = 'ss' where id in (select id from xxx where xx = 'ss' limit 100)
目前代码是:
DB::table('customer') ->join('customer_group_details', 'customer.id', '=', 'customer_group_details.customer_id') ->where('customer_group_id', $customer_group_id) ->update([ 'customer.ascription' => $users[0] ]);
换成子查询,laravel中DB不好写吧
@WadeYu 改成where in 了,limit要拿到外面来写
update cy_customer set `cy_customer`.`ascription` = '3' where `cy_customer`.`id` in (select `cy_customer_group_details`.`customer_id` from `cy_customer_group_details` where `customer_group_id` = '5') limit 100;
我要举报该,理由是:
mysql 支持这样限制更新记录条数