首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > Mysql >

大量数据查询求解决方案!该怎么解决

2012-03-24 
大量数据查询求解决方案!本人遇到一个这样的问题,求各路神仙提供一种解决方法。现在有一张表(暂且叫 tab_tm

大量数据查询求解决方案!
本人遇到一个这样的问题,求各路神仙提供一种解决方法。

现在有一张表(暂且叫 tab_tmp)有80万条记录,其中有两个字段是 'deviceid'(设备ID)以及 'addtime'(记录添加时间),现在想在这张表里面查询所有不重复 'deviceid' 的记录,且这些 ‘addtime’ 是最大的。

[解决办法]
select a.* from tab_tmp as a inner join
(
select deviceid, count(*) as num
from tab_tmp
group by deviceid having num=1
) b
on a.deviceid=b.deviceid;
[解决办法]

SQL code
select * from tab_tmp as awhere not exists(select * from tab_tmp                   where a.devceid=devceid and addtime>a.addtime) 

热点排行