计算出各个连续3个月的通话费用的平均数 1 select area_code,bill_month, local_fare, 2 sum(local_fare) 3 over ( partition by area_code 4 order by to_number(bill_month) 5 range between 1 preceding and 1 following ) "3month_sum", 6 avg(local_fare) 7 over ( partition by area_code 8 order by to_number(bill_month) 9 range between 1 preceding and 1 following ) "3month_avg", 10 max(local_fare) 11 over ( partition by area_code 12 order by to_number(bill_month) 13 range between 1 preceding and 1 following ) "3month_max", 14 min(local_fare) 15 over ( partition by area_code 16 order by to_number(bill_month) 17 range between 1 preceding and 1 following ) "3month_min" 18 from ( 19 select area_code,bill_month,sum(local_fare) local_fare 20 from t 21 group by area_code,bill_month 22* ) SQL> /
Quote: 1 select bill_month,area_code,sum(local_fare) local_fare, 2 ratio_to_report(sum(local_fare)) over 3 ( partition by bill_month ) area_pct 4 from t 5* group by bill_month,area_code SQL> break on bill_month skip 1 SQL> compute sum of local_fare on bill_month SQL> compute sum of area_pct on bill_month SQL> /