当前位置: 代码迷 >> Sql Server >> 求:最小时间的记录,该如何解决
  详细解决方案

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

热度:98   发布时间:2016-04-27 16:45:29.0
求:最小时间的记录
表格如下:
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)
  相关解决方案