SQL查询帮助:在SQL中进行分组和排序

时间:2010-09-24 19:23:15

标签: sql tsql

我试图在SQL中实现这一点,假设我有一个如下表

ID       DATE
7   2009-12-06 
7   2009-01-06 
7   2009-12-19 
7   2009-12-09 
7   2009-20-06 
9   2009-07-06 
9   2009-11-06 
10  2009-01-06 
10  2010-12-06 
10  2009-04-06 
11  2009-08-06 
11  2009-10-16
11  2009-11-19
12  2009-12-26
13  2009-04-16 
13  2009-09-06 
14  2009-12-06 

我想获取每个ID的最新日期,例如,我正在尝试进行查询,这将给我这样的内容

ID    DATE

7     2009-12-19 
9     2009-11-06 
10    2010-12-06 
11    2009-11-19
13    2009-09-06
14    2009-12-06

由于

1 个答案:

答案 0 :(得分:4)

select ID, MAX(DATE) as DATE
from MyTable
group by ID
order by ID