select * from (
select modetype,received_qty, case when totalqty = 0 then 0
else (cast((calc_value/ totalqty) * 100 as number(5,2))) end as percentage
from (
select vital_dashboard_mv.modetype, vital_dashboard_mv.received_qty,
vital_dashboard_mv.received_qty as calc_value,
(SELECT sum(received_qty) from vital_dashboard_mv) totalqty
from vital_dashboard_mv where vital_dashboard_mv.period = 4
group by modetype, received_qty
)
union all
(
select 'Total', sum(vital_dashboard_mv.received_qty), null
from vital_dashboard_mv where vital_dashboard_mv.period = 4
)
) order by modetype
|