例如我有表如下结构,id,name,updatedate
表用来纪录每个人登陆系统的纪录,所以每登陆一次就会在表里面插入一条纪录,也就是同一个人可以有很多个条纪录只是时间不一样,现在我要取出每个人最新登陆系统时间的一个列表,请问这个怎么查询啊?

解决方案 »

  1.   

    例如我有表如下结构,id,name,updatedate
    表用来纪录每个人登陆系统的纪录,所以每登陆一次就会在表里面插入一条纪录,也就是同一个人可以有很多个条纪录只是时间不一样,现在我要取出每个人最新登陆系统时间的一个列表,请问这个怎么查询啊?select a.* from tb a,
    (select name , max(updatedate) updatedate from tb gruop by name) b
    where a.name = b.name and a.updatedate = b.updatedate
      

  2.   

    select a.* from tb a,
    (select name , max(updatedate) updatedate from tb group by name) b
    where a.name = b.name and a.updatedate = b.updatedate
      

  3.   

    select * from TAB a where id = (select top 1 id from TAB where name = a.name order by updatedate desc)
      

  4.   

    例如我有表如下结构,id,name,updatedate
    表用来纪录每个人登陆系统的纪录,所以每登陆一次就会在表里面插入一条纪录,也就是同一个人可以有很多个条纪录只是时间不一样,现在我要取出每个人最新登陆系统时间的一个列表,请问这个怎么查询啊?
    ----------------
    select id,max(updatedate) from t group by id
      

  5.   

    select * from tb a where not exists(select 1 from tb b where id=a.id and updatedate>a.updatedate)
      

  6.   

    select * from tb a where not exists(select 1 from tb b where id=a.id and updatedate>a.updatedate)
    这个是最专业的,呵呵!