mysql在update语句中使用分页查询limit [offset,] rows

  在update语句中 limit 前几条是没问题的,形如下面的写法

update temp_dj_purchase set flag = "1"  limit 1000

  对于特定情况下,需要分页update,使用其他字段作为筛选条件又不能完全筛选出中间的数据,这个时候需要写limit 10,1000,但是默认情况下会报错

[SQL]update temp_dj_purchase set flag = "1"  limit 0,  1000

[Err] 1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '  1000' at line 1

  解决方案是使用子查询,改为下面的写法:

update temp_dj_purchase set flag = "1"  where 
id  in (select id from
(select id from temp_dj_purchase 
order by createtime asc  limit  10, 1000)tmp)

猜你喜欢

转载自blog.csdn.net/weixin_43839871/article/details/130220770