例如我有表如下结构,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
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
select * from TAB a where id = (select top 1 id from TAB where name = a.name order by updatedate desc)
例如我有表如下结构,id,name,updatedate 表用来纪录每个人登陆系统的纪录,所以每登陆一次就会在表里面插入一条纪录,也就是同一个人可以有很多个条纪录只是时间不一样,现在我要取出每个人最新登陆系统时间的一个列表,请问这个怎么查询啊? ---------------- select id,max(updatedate) from t group by id
select * from tb a where not exists(select 1 from tb b where id=a.id and updatedate>a.updatedate)
select * from tb a where not exists(select 1 from tb b where id=a.id and updatedate>a.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
(select name , max(updatedate) updatedate from tb group by name) b
where a.name = b.name and a.updatedate = b.updatedate
表用来纪录每个人登陆系统的纪录,所以每登陆一次就会在表里面插入一条纪录,也就是同一个人可以有很多个条纪录只是时间不一样,现在我要取出每个人最新登陆系统时间的一个列表,请问这个怎么查询啊?
----------------
select id,max(updatedate) from t group by id
这个是最专业的,呵呵!