首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

求:最小时间的记录,该如何解决

2012-02-16 
求:最小时间的记录表格如下:idnumtime0129:100119:110248:27031.210:10031110:15求:idnum012024031.2[解决

求:最小时间的记录
表格如下:
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)

热点排行