SQL语句 查找唯一记录

来源:百度知道 编辑:UC知道 时间:2024/05/11 02:00:17
记录
编号 分数 时间
1 36.3 2009-1-1
2 22.3 2009-2-2
3 55.2 2009-1-3
1 66.6 2009-6-26
2 66.6 2009-6-26
我现在想查找同一个编号的最近一条记录;比如上面的记录查找的结果应该是
1 66.6 2009-6-26
2 66.6 2009-6-26
3 55.2 2009-1-3
谢谢!答案被采用加分

select T.编号,A.分数,T.时间 from tablename A,(select 编号,MAX(时间) as 时间 from tablename group by 编号) T where A.编号=T.编号 and A.时间=T.时间

select * from table1 a where exists(select 编号,max(时间) from table1 group by 编号 having 编号=a.编号 and max(时间)=a.时间)

SELECT * FROM TABLE
WHERE (时间 IN
(SELECT MAX(时间)
FROM TABLE
GROUP BY 编号))

select * from table_name where 时间 in
( select max(时间) form table_name group by 编号)

select * from 表名 where 编号 in (select 编号 from(select 编号,max(时间) from 表名 group by 编号) a)

select t1.* from table_name t1, table_name t2 where t1.编号=t2.编号 group by t1.编号,t1.分数,t1.时间
having t1.时间=max(t2.时间)