How to get LAST_VALUE from an Analytic Function within a report?
My analytical report has following sql:
SELECT....
DENSE_RANK() OVER (PARTITION BY pco.appropriation ORDER BY pco.appropriation,
pco.fiscal_year ASC NULLS LAST) "Duration Years",
SUM(pco.quantity) OVER (PARTITION BY sms.data_source ORDER BY
sms.data_source, cst.display_nm RANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT
ROW) "Quantity Cum",
FROM ........
I have a request to calculate the percentage value by dividing MAX or LASTVALUE of these two functions at current row level:_
%DENSE_RANK = LAST_VALUE of ? DENSE_RANK() OVER (PARTITION BY pco.appropriation ORDER BY pco.appropriation,
pco.fiscal_year ASC NULLS LAST) "Duration Years"
/ (divide by)
DENSE_RANK() OVER (PARTITION BY pco.appropriation ORDER BY pco.appropriation,
pco.fiscal_year ASC NULLS LAST) "Duration Years"
%SUM = LAST_VALUE of ? SUM(pco.quantity) OVER (PARTITION BY sms.data_source ORDER BY
sms.data_source, cst.display_nm RANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT
ROW) "Quantity Cum",
/ (divide by)
SUM(pco.quantity) OVER (PARTITION BY sms.data_source ORDER BY
sms.data_source, cst.display_nm RANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT
ROW) "Quantity Cum"
Example of report output:
DENSE RANK DENSE RANK % SUM SUM %
1 10% 10 10%
2 20% 20 20%
3 100% 30 100%
1 10% 10 10%
2 20% 20 20%
....... ........ ..... ......
I appreciate your help to implement LAST_VALUE function for this case. Many thanks in advance.
Rob.
Edited by: user10455955 on Dec 17, 2008 9:25 AM