表:TEST
NAME TIME VALUE
A 200608 23
B 200507 25
A 200511 28
C 200408 29
B 200607 20
C 200508 12
得下结果:
Name TIME VALUE
A 200507 28
B 200507 25
C 200408 29
...全文
22411打赏收藏
如何获得最大值的时间?
表:TEST NAME TIME VALUE A 200608 23 B 200507 25 A 200511 28 C 200408 29 B 200607 20 C 200508 12 得下结果: Name TIME VALUE A 200507 28 B 200507 25 C 200408 29
create table test([NAME] char(1),[TIME] char(6),VALUE int)
insert test(name,time,value)
select 'A','200608','23' union all
select 'A','200608','23' union all--这条是增加的测试数据,如果日期相同,则都会显示出来
select 'B','200507','25' union all
select 'A','200511','28' union all
select 'C','200408','29' union all
select 'B','200607','20' union all
select 'C','200508','12'
--select * from test
select * from test a
WHERE 1>(SELECT COUNT(*) FROM test b WHERE a.time<b.time and a.name=b.name)
drop table test