Select To_date (: fr_date, ' Yyyy-mm-dd ') f_date,to_date (: to_date, ' Yyyy-mm-dd ') T_date,nnd,count (distinct memb_id) memb _count,count (bill_id) bill_count,sum (Bill_money) Pay_count,to_char (Round (sum (bill_money) *100/sum (SUM (Bill_money) )Over (),2), ' 990.99 ') | | ' % ' percent from (
Select Case when C.year_old>=1 and c.year_old<=10 then ' 1-10 '
When c.year_old>=11 and c.year_old<=20 then ' 11-20 '
When c.year_old>=21 and c.year_old<=30 then ' 21-30 '
When c.year_old>=31 and c.year_old<=40 then ' 31-40 '
When c.year_old>=41 and c.year_old<=50 then ' 41-50 '
Else ' over 50 years old ' end as Nnd,d.bill_id,d.memb_id,d.bill_date,d.bill_money,year_old
From
(Select Memb_id,floor (Months_between (sysdate,birth_date)/12) as Year_old from tb_ax001 a) C,
(select Bill_id,memb_id,bill_date,bill_money from tb_ax006 b where b.bill_date between to_date (: Fr_date, ' yyyy-mm-dd ') and To_date (: to_date, ' yyyy-mm-dd ') +0.99999) d
where c.memb_id (+) = d.memb_id) E
GROUP BY Nnd
ORDER BY Nnd
--sum (SUM (Bill_money)) over () total amount
Oracle in-Over ()