How to make aggregate function work on non-sort key

"When you need a value from the first or last row of a sorted group, but the needed 

value is not the sort key, the FIRST and LAST functions eliminate the need for 

self-joins or views and enable better performance."

 

SELECT department_id,
MIN(salary) KEEP (DENSE_RANK FIRST ORDER BY commission_pct) "Worst",
MAX(salary) KEEP (DENSE_RANK LAST ORDER BY commission_pct) "Best"
   FROM employees
   GROUP BY department_id;

 

From Oracle Document

你可能感兴趣的:(oracle)