我有一个表,其中包含如下记录
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 现在,我只想在result 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 发布于 2016-05-25 17:14:36
希望这能有所帮助。
SELECT
Unit,
Rate,
MAX(DateEffected) AS MaxDateEffected
FROM TableName
GROUP BY Unit,Rate发布于 2016-05-25 17:16:04
您可以使用来执行以下操作:
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 = 1https://stackoverflow.com/questions/37432538
复制相似问题