码迷,mamicode.com
首页 > 数据库 > 详细

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

时间:2018-12-24 17:20:32      阅读:211      评论:0      收藏:0      [点我收藏+]

标签:最新   table   sel   max   rom   时间   join   not   HERE   

 -- 方法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 

  

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

标签:最新   table   sel   max   rom   时间   join   not   HERE   

原文地址:https://www.cnblogs.com/ttty/p/10169439.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!