求:最小时间的记录
表格如下:
id num time
01 2 9:10
01 1 9:11
02 4 8:27
03 1.2 10:10
03 11 10:15
求:
id num
01 2
02 4
03 1.2
------解决方案--------------------create table T(id varchar(10), num decimal(10, 1), [time] varchar(10))
insert T select '01 ', 2, '9:10 '
union all select '01 ', 1, '9:11 '
union all select '02 ', 4, '8:27 '
union all select '03 ', 1.2, '10:10 '
union all select '03 ', 11, '10:15 '
select * from t as tmp
where not exists(select 1 from t where id=tmp.id and time <tmp.time)
--result
id num time
---------- ------------ ----------
01 2.0 9:10
02 4.0 8:27
03 1.2 10:10
(3 row(s) affected)