select * from tablea a where not exists(select * from tablea where a.name = name and a.time = time and a.Atime < atime)
create table tr (id int, name varchar(8),time datetime,atime datetime) insert into tr select '1','ab','2004/12/20','2004/12/21' union all select '2','ab','2004/12/20','2004/12/22select * from tr a where not exists(select * from tr where a.name = name and a.time = time and a.Atime < atime)
select * from tableA as a where Atime =(select max(Atime) from tableA where a.name = name and a.time = time)
SELECT a.* FROM tableA a WHERE a.Atime IN ( SELECT MAX(b.Atime) FROM tableA b GROUP BY b.name,b.time HAVING b.name = a.name AND b.time = a.time ) ORDER BY a.ID
from tablea a
where not exists(select * from tablea where a.name = name and a.time = time and a.Atime < atime)
insert into tr select '1','ab','2004/12/20','2004/12/21'
union all
select '2','ab','2004/12/20','2004/12/22select *
from tr a
where not exists(select * from tr where a.name = name and a.time = time and a.Atime < atime)
where Atime =(select max(Atime) from tableA where a.name = name and a.time = time)
SELECT a.* FROM tableA a WHERE a.Atime IN
(
SELECT MAX(b.Atime) FROM tableA b GROUP BY b.name,b.time HAVING b.name = a.name AND b.time = a.time
)
ORDER BY a.ID