一个SQL update语句

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

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;

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值