Paraphrasing my answer here:
MAX(ra.address) KEEP(DENSE_RANK LAST ORDER BY ra.startdate)
The statement can be considered in (roughly) right-to-left order:
ORDER BY ra.startdate
means order the rows, within each group, by the startdate
column of the ra
aliased table (implicitly using ASC
ending order); then
KEEP (DENSE_RANK LAST
means give a (consecutive) ranking to those ordered rows within each group (rows with identical values for the ordering columns will be given the same rank) and KEEP
only those rows that are LAST
in the ranking (i.e. the rows with the maximum startdate
); and finally
MAX(ra.address)
for the remaining kept rows of each group, return the maximum salary.
You are finding the maximum address
value out of the rows with the maximum (latest) startdate
for each group.
Without the KEEP
clause:
MAX(ra.startdate)
Means find the maximum (latest) of the startdate
column for each group.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…