ORACLE OVER (PARTITION BY ... ORDER BY ...) aggregate function usage

ORACLE OVER (PARTITION BY ... ORDER BY ...) aggregate function usage

Requirement:
Divide into groups according to the type name, and take the latest record with the type name "AAA"
Application scenario:
When table A and table B have a 1:n relationship in production, take the latest (oldest) or smallest record in table B (Maximum) A certain value is associated with table A.
It may be difficult for some Taoists to understand this sentence, and they will think why the two tables are not directly associated to nest to get the most value. I know what you think. This application scenario is similar to The two things are fine (this is advanced sql), and I will understand when I actually encounter them.

SELECT *
  FROM (SELECT ROW_NUMBER() OVER(PARTITION BY T.ID ORDER BY T.UPDATE_DATE DESC) RN,
               T.*
          FROM TABLE T
         WHERE T.TYPE_NAME = 'AAA') P
 WHERE P.RN = 1

Guess you like

Origin blog.csdn.net/qq_37980551/article/details/89389513