问题聚集度Hive SQL

问题聚集度:最小的分母占比,贡献最多的分子占比,即小规模贡献大问题。

sql 复制代码
select
	city_name
	,user_id
	,rf_type
	,deal_ord_cnt
	,sale_amt
	,rf_ord_cnt
	,rf_amt
	,rf_ra
	,rf_amt_ra
	,rf_all
	,ord_cnt_all
	,rf_gx
	,ord_cnt_gx
	,del_gx
	,row_number() over(partition by rf_type order by del_gx desc,rf_ra desc,user_id) as rn    -- 贡献差由大到小排序
	,sum(rf_ord_cnt) over(partition by rf_type order by del_gx desc,rf_ra desc,user_id) as rf_ordby    -- 分子累计
	,sum(deal_ord_cnt) over(partition by rf_type order by del_gx desc,rf_ra desc,user_id) as ord_cnt_ordby    -- 分母累计
	,(sum(rf_ord_cnt) over(partition by rf_type order by del_gx desc,rf_ra desc,user_id)) / rf_all as rf_ordby_ra    -- 分子累计占比曲线
	,(sum(deal_ord_cnt) over(partition by rf_type order by del_gx desc,rf_ra desc,user_id)) / ord_cnt_all as ord_cnt_ordby_ra    -- 分母累计占比曲线
	,((sum(rf_ord_cnt) over(partition by rf_type order by del_gx desc,rf_ra desc,user_id)) / rf_all -
		(sum(deal_ord_cnt) over(partition by rf_type order by del_gx desc,rf_ra desc,user_id)) / ord_cnt_all) del1    -- 累计贡献差
	,lead(((sum(rf_ord_cnt) over(partition by rf_type order by del_gx desc,rf_ra desc,user_id)) / rf_all -
		(sum(deal_ord_cnt) over(partition by rf_type order by del_gx desc,rf_ra desc,user_id)) / ord_cnt_all),1) 
			over(partition by rf_type order by del_gx desc,rf_ra desc,user_id) - 
			((sum(rf_ord_cnt) over(partition by rf_type order by del_gx desc,rf_ra desc,user_id)) / rf_all -
		(sum(deal_ord_cnt) over(partition by rf_type order by del_gx desc,rf_ra desc,user_id)) / ord_cnt_all) as del2    --二阶差分,大于0的部分为聚集部分
from
(
select
	city_name
	,user_id
	,deal_ord_cnt  -- 分母
	,sale_amt
	,rf_cancel_ord_cnt as rf_ord_cnt    -- 分子
	,rf_qx_amt as rf_amt
	,rf_cancel_ord_cnt / deal_ord_cnt as rf_ra    -- 监控指标
	,rf_qx_amt/sale_amt as rf_amt_ra
	,sum(rf_cancel_ord_cnt) over() as rf_all
	,sum(deal_ord_cnt) over() as ord_cnt_all
	,rf_cancel_ord_cnt / (sum(rf_cancel_ord_cnt) over()) as rf_gx    -- 分子贡献
	,deal_ord_cnt / (sum(deal_ord_cnt) over()) as ord_cnt_gx    -- 分母贡献
	,rf_cancel_ord_cnt / (sum(rf_cancel_ord_cnt) over()) - deal_ord_cnt / (sum(deal_ord_cnt) over()) as del_gx    -- 贡献差值
	,'取消订单' as rf_type
from table_refund
where rf_cancel_ord_cnt > 0    -- 限定分子>0
) t0
相关推荐
薛不痒19 分钟前
MySQL中使用SQL语言
数据库·sql·mysql
五阿哥永琪34 分钟前
SQL中的函数--开窗函数
大数据·数据库·sql
码农阿豪1 小时前
告别兼容焦虑:电科金仓 KES 如何把 Oracle 的 PL/SQL 和 JSON 业务“接住”
数据库·sql·oracle·json·金仓数据库
曹牧1 小时前
Oracle SQL 中,& 字符
数据库·sql·oracle
小小测试开发2 小时前
实战派SQL性能优化:从语法层面攻克项目中的性能瓶颈
android·sql·性能优化
Hello.Reader3 小时前
Flink SQL 的 UNLOAD MODULE 模块卸载、会话隔离与常见坑
大数据·sql·flink
Bug.ink3 小时前
BUUCTF——WEB(2)
数据库·sql·网络安全·buuctf
代码or搬砖5 小时前
SQL核心语法总结:从基础操作到高级窗口函数
java·数据库·sql
Hello.Reader6 小时前
Flink SQL 的 LOAD MODULE 深度实战——加载 Hive 模块、理解模块发现与常见坑
hive·sql·flink
jfqqqqq6 小时前
postgres查询、重设自增序列的起始值
数据库·sql·postgres·自增序列