如何用Oracle RATIO_TO_REPORT计算总数百分比

开发者在线 Builder.com.cn 更新时间:2007-07-27作者:开发者在线 来源:开发者在线

Listing B

col order_total format 999,999.00
col pct_total format 999.00

SELECT
   sales_rep_id, 
   customer_id, 
   order_total,
   ROUND(100*ratio_to_report(order_total) 
      OVER (PARTITION BY customer_id),2) pct_total
FROM
   orders
WHERE
   sales_rep_id = 163
ORDER BY
   sales_rep_id, customer_id, order_id/

SQL> @ratioreport_b

SALES_REP_ID CUSTOMER_ID ORDER_TOTAL PCT_TOTAL                                  
------------ ----------- ----------- ---------                                  
         163         102    5,610.60     34.78                                  
         163         102   10,523.00     65.22                                  
         163         103       78.00       .57                                  
         163         103   13,550.00     99.43                                  
         163         105    1,926.60    100.00                                  
         163         106    5,546.60    100.00                                  
         163         117    3,878.40    100.00                                  
         163         147    1,500.80    100.00                                  
         163         149    9,055.00    100.00                                  
         163         156   68,501.00    100.00                                  
         163         157    7,110.30    100.00                                  
         163         160      969.20    100.00                                  

12 rows selected.

SQL> spool off

用户评论

  • 用户名
  • 评论内容