select * from 数据表 a
where 时间 in(
select top 2 时间 from 数据表 where 姓名=a.姓名 and 日期=a.日期 order by 时间
union all
select top 2 时间 from 数据表 where 姓名=a.姓名 and 日期=a.日期 order by 时间 desc)
刚才看错了以为最先,或最后的一条
select * from 数据表 a
where 时间 in(
select top 2 时间 from 数据表 where 姓名=a.姓名 and convert(char(10),时间,120)=convert(char(10),a.时间,120) order by 时间
union all
select top 2 时间 from 数据表 where 姓名=a.姓名 and convert(char(10),时间,120)=convert(char(10),a.时间,120) order by 时间 desc )