presto group by 注意事项

该博客分析了2021年8月之后风豹科技与自有资产平台的进件数量,通过不同风险状态的计数来揭示渠道绩效。groupby 1,2 的用法在这里指的是按日期和渠道类型进行聚合,同时观察风险评估指标的变化趋势。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1


--渠道方进件数
select 
a.etl_date
,if(b.platform_nm='风豹科技' ,'风豹','自有资产')
,count(a.loan_id) as c1
,count(case when a.intorisk_state=10190 then 1 else null end) c2
,count(case when a.intorisk_state=10210 then 1 else null end) c3
from 
(
select *  from edw_dwd.d_ph_jj_on_flow_fact_d_ss 
where etl_date >= '2021-08-01' 
and substring(app_loan_time,1,10) = etl_date --申请时间
) a 
 join 
 (
 select *  from dm_fk.agg_speed_withhold_aggregation 
where etl_date >= '2021-08-01' 
and platform_nm in('风豹科技','北京小贷', '猪八戒小贷','华北小贷')
 ) b 
 on a.loan_id = b.intpc_id 
 group by 
a.etl_date
,b.platform_nm
 order by 
a.etl_date
,b.platform_nm

 

2


--渠道方进件数
select 
a.etl_date
,if(b.platform_nm='风豹科技' ,'风豹','自有资产')
,count(a.loan_id) as c1
,count(case when a.intorisk_state=10190 then 1 else null end) c2
,count(case when a.intorisk_state=10210 then 1 else null end) c3
from 
(
select *  from edw_dwd.d_ph_jj_on_flow_fact_d_ss 
where etl_date >= '2021-08-01' 
and substring(app_loan_time,1,10) = etl_date --申请时间
) a 
 join 
 (
 select *  from dm_fk.agg_speed_withhold_aggregation 
where etl_date >= '2021-08-01' 
and platform_nm in('风豹科技','北京小贷', '猪八戒小贷','华北小贷')
 ) b 
 on a.loan_id = b.intpc_id 
 group by 
a.etl_date
,if(b.platform_nm='风豹科技' ,'风豹','自有资产')
 order by 
a.etl_date
,if(b.platform_nm='风豹科技' ,'风豹','自有资产')

 

3


--渠道方进件数
select 
a.etl_date
,if(b.platform_nm='风豹科技' ,'风豹','自有资产')
,count(a.loan_id) as c1
,count(case when a.intorisk_state=10190 then 1 else null end) c2
,count(case when a.intorisk_state=10210 then 1 else null end) c3
from 
(
select *  from edw_dwd.d_ph_jj_on_flow_fact_d_ss 
where etl_date >= '2021-08-01' 
and substring(app_loan_time,1,10) = etl_date --申请时间
) a 
 join 
 (
 select *  from dm_fk.agg_speed_withhold_aggregation 
where etl_date >= '2021-08-01' 
and platform_nm in('风豹科技','北京小贷', '猪八戒小贷','华北小贷')
 ) b 
 on a.loan_id = b.intpc_id 
 group by 
1,2
 order by 
1,2

 结论:

1、group by 1,2可以指代select后面的列

2、group by 的列涉及到计算或者判断时,不能只写列名.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值