我有一张表,其中包含
等记录Unit Rate Date-effected
-------------------------------------------
ALHA ILS 2014-03-02 00:00:00.000
ALHA ILS 2014-08-02 00:00:00.000
BUCK ILS 2013-02-14 00:00:00.000
BUCK ILS 2014-03-02 00:00:00.000
BUCK ILS 2014-08-02 00:00:00.000
CASC ILD 2013-02-14 00:00:00.000
CASC ILD 2014-03-02 00:00:00.000
CASC ILD 2014-08-02 00:00:00.000
现在,我只想在结果table
中选择最大日期值记录。是,
Unit Rate DateEffected
-------------------------------------------
ALHA ILS 2014-08-02 00:00:00.000
BUCK ILS 2014-08-02 00:00:00.000
CASC ILD 2014-08-02 00:00:00.000
答案 0 :(得分:2)
希望这有帮助。
0 path
答案 1 :(得分:2)
您可以使用ROW_NUMBER
:
SELECT Unit, Rate, DateEffected
FROM (
SELECT Unit, Rate, DateEffected,
ROW_NUMBER() OVER (PARTITION BY Unit
ORDER BY DateEffected DESC) AS rn
FROM mytable) AS t
WHERE t.rn = 1