问题聚集度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
相关推荐
麦聪聊数据2 小时前
Web 原生架构如何重塑企业级数据库协作流?
数据库·sql·低代码·架构
qq_12498707534 小时前
基于Hadoop的信贷风险评估的数据可视化分析与预测系统的设计与实现(源码+论文+部署+安装)
大数据·人工智能·hadoop·分布式·信息可视化·毕业设计·计算机毕业设计
Apple_羊先森6 小时前
ORACLE数据库巡检SQL脚本--19、磁盘读次数最高的前5条SQL语句
数据库·sql·oracle
十月南城7 小时前
Hive与离线数仓方法论——分层建模、分区与桶的取舍与查询代价
数据仓库·hive·hadoop
l1t8 小时前
DeepSeek总结的PostgreSQL的GPT推理SQL移植到DuckDB的性能优化方法
sql·gpt·postgresql
鹏说大数据9 小时前
Spark 和 Hive 的关系与区别
大数据·hive·spark
B站计算机毕业设计超人9 小时前
计算机毕业设计Hadoop+Spark+Hive招聘推荐系统 招聘大数据分析 大数据毕业设计(源码+文档+PPT+ 讲解)
大数据·hive·hadoop·python·spark·毕业设计·课程设计
B站计算机毕业设计超人9 小时前
计算机毕业设计hadoop+spark+hive交通拥堵预测 交通流量预测 智慧城市交通大数据 交通客流量分析(源码+LW文档+PPT+讲解视频)
大数据·hive·hadoop·python·spark·毕业设计·课程设计
AI架构师小马9 小时前
Hive调优手册:从入门到精通的完整指南
数据仓库·hive·hadoop·ai
数据架构师的AI之路9 小时前
深入了解大数据领域Hive的HQL语言特性
大数据·hive·hadoop·ai