数据库的一个表里筛选出每一人的时间最新的一条记录

Posted 张怼怼

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了数据库的一个表里筛选出每一人的时间最新的一条记录相关的知识,希望对你有一定的参考价值。

 -- 方法1  
    select a.*  
     from table1 a  
     where not exists(select 1  
                      from table1 b  
                      where b.name=a.name and b.gdtime>a.gdtime)  
      
    -- 方法2  
    select a.*  
     from table1 a  
     inner join  
     (select name,  
             max(gdtime) ‘maxgdtime‘  
      from table1  
      group by name) b on a.name=b.name and a.gdtime=b.maxgdtime 

  

以上是关于数据库的一个表里筛选出每一人的时间最新的一条记录的主要内容,如果未能解决你的问题,请参考以下文章