小编典典

Oracle组使用最小日期

sql

我有这样的声明:

 select REFNUMBER,
        SomeDate,
        Somecolumn1,
        Somecolumn2
 from Table

如何选择与REFNUMBER分组的最低日期关联的行?


阅读 173

收藏
2021-05-16

共1个答案

小编典典

使用ROW_NUMBER()分析功能:

SELECT *
FROM   (
  SELECT REFNUMBER,
         SomeDate,
         Somecolumn1,
         Somecolumn2,
         ROW_NUMBER() OVER ( PARTITION BY REFNUMBER ORDER BY SomeDate ) As rn
  FROM   Table
)
WHERE  rn = 1
2021-05-16