Oracle group using min date
问题 I have a statement like this: select REFNUMBER, SomeDate, Somecolumn1, Somecolumn2 from Table How can I select the row associated with the lowest date grouped by REFNUMBER ? 回答1: Use the ROW_NUMBER() analytic function: SELECT * FROM ( SELECT REFNUMBER, SomeDate, Somecolumn1, Somecolumn2, ROW_NUMBER() OVER ( PARTITION BY REFNUMBER ORDER BY SomeDate ) As rn FROM Table ) WHERE rn = 1 回答2: Use the first/last aggregate function and avoid a subquery: select refnumber, min(somedate) as somedate, min