问题聚集度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
相关推荐
像豆芽一样优秀1 小时前
深入理解与应用SQL递归CTE处理层级数据
大数据·hive·sql
【赫兹威客】浩哥2 小时前
【赫兹威客】伪分布式Hadoop测试教程
大数据·hadoop·分布式
Knight_AL3 小时前
掌握 SQL 窗口函数:分组、排名与最新记录获取的最佳实践
数据库·sql·mysql·oracle
Hello.Reader3 小时前
Flink on Hadoop YARN 从 0 到可上线的 Session / Application 部署指南
大数据·hadoop·flink
B站计算机毕业设计超人3 小时前
计算机毕业设计Python+Django考研院校推荐系统 考研分数线预测系统 大数据毕业设计 (代码+LW文档+PPT+讲解视频)
大数据·人工智能·hive·python·django·毕业设计·课程设计
what丶k3 小时前
SQL三大核心查询语法(WHERE/ORDER BY/GROUP BY)综合运用指南
大数据·数据库·sql·mysql·面试
霑潇雨3 小时前
题解 | 分析每个商品在不同时间段的销售情况
数据库·sql·算法·笔试
王五周八3 小时前
从测试到执行计划:拆解 SQL 性能坑的底层逻辑
数据库·sql
Eugene Jou4 小时前
Dinky+Flink SQL达梦数据库实时同步到Doris简单实现
数据库·sql·flink
玄同7654 小时前
SQLAlchemy 会话管理终极指南:close、commit、refresh、rollback 的正确打开方式
数据库·人工智能·python·sql·postgresql·自然语言处理·知识图谱