select * from 表A a
inner join
(select stusent_id, max(time) as max_time from A GROUP BY stusent_id) b
on a.stusent_id=b.stusent_id
inner join
(select stusent_id, max(time) as max_time from A GROUP BY stusent_id) b
on a.stusent_id=b.stusent_id
from 表A a
where not exists(select 1 from 表A where stusent_id=a.stusent_id and time>a.time)
(SELECT stusent_id, MAX([time]) AS Expr2
FROM Test051114
GROUP BY stusent_id) b on a.stusent_id=b.stusent_id and a.[time]=b.Expr2
(
id int,
stusent_id varchar(30),
time varchar(30),
dep varchar(30)
)insert into 表A
select 1,'001','20041110','计算机' union all
select 2,'001','20050910','工商管理学' union all
select 3,'002','20031010','计算机' union all
select 4,'002','20051010','自动化'select 表A.* from 表A,
(select stusent_id,max(time) as time from 表A group by stusent_id) T2
where 表A.stusent_id=T2.stusent_id
and 表A.time=T2.time
order by id
where exists (select 1 from 表A where a.stusent_id=stusent_id group by stusent_id having max(time)=a.time)