问题聚集度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
相关推荐
持敬chijing13 小时前
Web渗透之SQL注入-二次注入(Second-Order SQL Injection)
sql·安全·web安全·网络安全·网络攻击模型·安全威胁分析
段一凡-华北理工大学17 小时前
工业领域的Hadoop架构学习~系列文章20:故障诊断与根因分析 - 从表象到本质的智能推理
大数据·人工智能·hadoop·学习·架构·高炉炼铁·工业智能体
Francek Chen18 小时前
【大数据处理与分析】MapReduce:05 MapReduce的具体应用
大数据·hadoop·分布式·mapreduce
这个DBA有点耶19 小时前
时序数据库深度对比:2026 年主流 TSDB 架构演进与选型指南
数据库·sql·云原生·架构·运维开发·时序数据库
计算机安禾19 小时前
【数据库系统原理】第9篇:SQL的结构化思维:DDL、DML与DCL的职责分离
数据库·sql·oracle
计算机安禾19 小时前
【数据库系统原理】第12篇:视图机制:外模式在SQL层级的逻辑数据独立性实现
数据库·sql·oracle
前进的李工19 小时前
MySQL性能优化:索引与子查询实战技巧
数据库·sql·mysql·性能优化
迷枫71220 小时前
达梦 SQL 执行计划操作符与 TRACE、ET 学习笔记
笔记·sql
知识分享小能手20 小时前
Hadoop学习教程,从入门到精通, 部署Hadoop 3.x — 知识点详解(2)
大数据·hadoop·学习
念越20 小时前
SQL 基础语法复习
数据库·sql·数据库系统概论