select * from table1 where 时间 = (select max(时间) from table1) or 时间 = (select min(时间) from table1)
select top 1 * from 表 order by 时间 union all select top 1 * from 表 order by 时间 desc
若有主键id ---------最晚 select * from 表 tmp where 时间=(select max(时间) from 表 where tmp.id=id) ---------最早 select * from 表 tmp where 时间=(select min(时间) from 表 where tmp.id=id)
where 时间 = (select max(时间) from table1)
or 时间 = (select min(时间) from table1)
union all
select top 1 * from 表 order by 时间 desc
---------最晚
select * from 表 tmp where 时间=(select max(时间) from 表 where tmp.id=id)
---------最早
select * from 表 tmp where 时间=(select min(时间) from 表 where tmp.id=id)
--- --- --- ---
1 001 rre 2003-01-01 01:01:01
2 003 ete 2003-01-11 01:01:02
3 001 wez 2003-01-21 03:02:01
4 005 eee 2003-01-01 01:06:01
5 005 weo 2003-01-01 02:01:01
现在的要求是找出a中不同字段值记录的最大时间或最小时间记录
即:001符合最大时间的是第三条记录,最小时间的是第一条记录