I have written a complex SQL query with Oracle in which I want to use two analytic function over the same partition.
Let's be quite simple but not too much:
SELECT col1,
MAX(col2) OVER(PARTITION BY col3, col4, col5, col6,
CASE WHEN col7 LIKE 'foo'
THEN SUBSTR(col7,1,5)
ELSE col7
END
ORDER BY col5 ASC, col6 DESC),
MIN(col2) OVER(PARTITION BY col3, col4, col5, col6,
CASE WHEN col7 LIKE 'foo'
THEN SUBSTR(col7,1,5)
ELSE col7
END
ORDER BY col5 ASC, col6 DESC)
FROM my_table;
Is there a more elegant syntax for factoring the PARTITION BY
clause?
Thank you.
MAX
andMIN
and alsocol5
andcol6
are in thepartition
and theorder by
, theorder by
clause for each column appears to be redundant. – Shinbone