有如下數據
id date value1 value2
1 2015-01-01 100 200
1 2015-01-02 210 90
2 2015-01-02 110 220
2 2015-01-03 120 140
2 2015-01-04 50 50
3 2015-01-01 100 100
按照id分組,取日期最大的那條記錄,並且獲得value1 value2
結果
id date value1 value2
1 2015-01-02 210 90
2 2015-01-04 50 50
3 2015-01-01 100 100
請問怎麼做
select id, max([date]) as [date], (select max(value1 from table where [date] = max[date]) as value1, (select max(value2 from table where [date] = max[date]) as value2 from table