ratio_to_report()over() 第一个括号中就是分子,over() 括号中就是分母,分母缺省就是整个占比,至于你说的select中没有销售机型 没看懂
解决方案 »
- 如何用SQL语句获取Oracle的数据类型??
- ORACLE 9i 的DATE 型字段中出现了"2006-12-11 下午 08:04:04"
- 【偶结贴一向很快 ^_^】问个简单的存储过程代码----错在哪里?
- oracle数据库恢复
- 数据库 字段 数据类型的疑问?
- 在ORACLE数据库进行过哪些改变之后,数据库需要进行重新备份呢?
- 哪儿有sqlplus下载!请留个下载地址 !或者请mail给我 : [email protected] !
- 保存数据时出错:
- 如何建立好监听器 ?如何配置好客户端 net configuration
- pl/sql :sql statement ignoed 求教各位大神 谢谢
- 请教Oracle中存储过程参数问题
- 急急急!!!oracle job submit 提示 PLS-00357: 在此上下文中不允许表, 视图或序列引用 'LOTNO_SEQUENCE'
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/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.
(select 'c001' cust_id, 'n01' m_type, '1' c_num
from dual
union all
select 'c001' cust_id, 'n01' m_type, '2' c_num
from dual
union all
select 'c001' cust_id, 'n03' m_type, '3' c_num
from dual
union all
select 'c002' cust_id, 'n01' m_type, '1' c_num
from dual
union all
select 'c002' cust_id, 'n02' m_type, '2' c_num
from dual
union all
select 'c002' cust_id, 'n03' m_type, '3' c_num from dual)
select m.cust_id, m.m_type, 100*round(sum(bfb),4) bfb
from (select cust_id,
m_type,
ratio_to_report(c_num) over(partition by cust_id) bfb
from t) m
group by m.cust_id, m.m_type order by cust_id,m.m_type
给你个测试用例,你的数据存在同一个客户,同一个机型的吧,不然只要内层的sql就行了