码迷,mamicode.com
首页 > 数据库 > 详细

一个SQL update语句

时间:2014-05-10 04:22:58      阅读:423      评论:0      收藏:0      [点我收藏+]

标签:sql   mysql   

需要每隔一段时间选取最老的商户更新时间戳: 

update DP_Shop set DP_Shop.LastDate = now() where DP_Shop.ShopId in (select ShopId from DP_Shop order by LastDate limit 5); 

ERROR 1235 (42000): This version of MySQL doesn‘t yet support ‘LIMIT & IN/ALL/ANY/SOME subquery‘

多加一层: 

update DP_Shop set DP_Shop.LastDate = now() where DP_Shop.ShopId in (select t.ShopId from (select ShopId from DP_Shop order by LastDate limit 5) as t); 

可以work,但不高效,考虑下怎么优化。

最后是用临时表:

start transaction;

create temporary table tmp1986 (select ShopId from DP_Shop order by LastDate limit 1000);

update DP_Shop inner join tmp1986 on DP_Shop.ShopId = tmp1986.ShopId set LastDate = now();

DROP TABLE tmp1986; 

commit;

一个SQL update语句,布布扣,bubuko.com

一个SQL update语句

标签:sql   mysql   

原文地址:http://blog.csdn.net/jollyjumper/article/details/25427361

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!