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

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

本人遇到一个这样的问题,求各路神仙提供一种解决方法。

现在有一张表(暂且叫 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 a
where not exists(select * from tab_tmp 
                  where a.devceid=devceid and addtime>a.addtime)


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

相关文章:

你感兴趣的文章:

标签云: