设为首页 加入收藏

TOP

一个SQLupdate语句
2015-07-24 10:40:09 来源: 作者: 【 】 浏览:2
Tags:一个 SQLupdate 语句

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

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高级(5) 下一篇SQL高级(7)Date函数

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容:

·有没有哪些高效的c++ (2025-12-27 08:20:57)
·Socket 编程时 Accep (2025-12-27 08:20:54)
·计算机网络知识点总 (2025-12-27 08:20:52)
·一篇说人话的文章, (2025-12-27 07:50:09)
·Python Web框架哪家 (2025-12-27 07:50:06)