2010-09-24 82 views
1

我試圖在SQL實現這一目標的排序,可以說,我有一個像下面SQL查詢幫助:分組和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 

感謝

回答

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

咄!感謝您的幫助 – Joe 2010-09-24 19:28:12

+0

引用Jimi Hendrix:嘿喬,你在哪裏去接受RedFilter的回答? :) – 2010-09-24 19:30:17

+0

@ djaccobson - 網站不允許接受答案,直到15分鐘後:) – Joe 2010-09-24 19:34:49