PostgreSQL_case when
2024-05-09 16:08:42
描述
查询6月份借款用户,在7.15的d1,d2的逾期率,分新老用户
- 用户借款时间为6.01-6.31
- 根据逾期天数分为d1和d2,d1表示逾期大于1天
- brrank确定新用户和老用户,新用户brrank=1,老用户brrank>1
- psperdno = 1 表示第一期借款
-- d1 新用户(brrank=1)d2(修改latedays > 1)
select
count(distinct custid) "总人数",
count(distinct case when latedays > 0 then custid end) "d1新用户逾期人数",
count(distinct case when latedays > 0 then custid end)*1.0/count(*) "d1新用户逾期率"
from
transformdata.xsfinrank
where brrank = 1 and psperdno = 1 and ('2018-06-30'::date - givemoneydate) >= 0 and ('2018-06-01'::date - givemoneydate) <= 0;-- d1 老用户(brrank>1)d2(修改latedays > 1)
select
count(distinct custid) "总人数",
count(distinct case when latedays > 0 then custid end) "d1老用户逾期人数",
count(distinct case when latedays > 0 then custid end)*1.0/count(*) "d1老用户逾期率"
from
transformdata.xsfinrank
where brrank > 1 and psperdno = 1 and ('2018-06-30'::date - givemoneydate) >= 0 and ('2018-06-01'::date - givemoneydate) <= 0;
通过case when合并
select
case when brrank=1 then 1 when brrank > 1 then 2 end brrank,
count(distinct custid) "总人数",
count(distinct case when latedays > 0 then custid end) "d1逾期人数",
count(distinct case when latedays > 0 then custid end)*1.0/count(*) "d1逾期率",
count(distinct case when latedays > 1 then custid end) "d2逾期人数",
count(distinct case when latedays > 1 then custid end)*1.0/count(*) "d2逾期率"
from
transformdata.xsfinrank
where (givemoneydate between to_date('2018-06-01','YYYY-MM-DD') and to_date('2018-06-30','YYYY-MM-DD'))
and psperdno = 1 --第一期
group by 1;
描述2
计算老用户逾期人数中 前期借款逾期 超过15天的人数
select
count(distinct a.custid) "逾期超过15"
from
transformdata.xsfinrank a
inner join
(
select
custid,
brrank
from
transformdata.xsfinrank
where (givemoneydate between to_date('2018-06-01','YYYY-MM-DD') and to_date('2018-06-30','YYYY-MM-DD'))
and psperdno = 1 and brrank >1 --第一期
)b
on a.custid = b.custid
where a.brrank<b.brrank and latedays > 15
select
a.custid,
max(a.latedays)
from
transformdata.xsfinrank a
inner join
(
select
custid,
brrank
from
transformdata.xsfinrank
where (givemoneydate between to_date('2018-06-01','YYYY-MM-DD') and to_date('2018-06-30','YYYY-MM-DD'))
and psperdno = 1 and brrank >1 --第一期
)b
on a.custid = b.custid and a.brrank<b.brrank
group by 1 order by 2 desc;
PostgreSQL_case when相关推荐
最新文章
- android 多参数,玩转Android monkey之多参数实战
- laravel 分词搜索匹配度_SEO除了“中文分词”还有“文本分析”- 搜狗蜘蛛池博客...
- tomcat闪退没有报错_Appium在Android平台几种常见报错的解决方案
- =空值返回空值_@ParameterizedTest在@CvsSource中具有空值
- Android M 新的运行时权限开发者需要知道的一切
- AOJ0008 Sum of 4 Integers【暴力】
- 驳熊节和Martin Fowler的Java消亡论!
- WebDAV被启用(转)
- Flume 1.8.0 用户指南(Flume 1.8.0 User Guide)
- 【Java算法】Java抽奖算法,适用于各种抽奖
- 孙鑫老师的帮助文档 MSDN Library 2001January 下载地址
- Qt日历控件显示周数为:日一二三四五六
- java 合并多个文件_java中如何将两个文件合并到另一个文件
- 天牛须matlab,BAS天牛须搜索优化算法.pdf
- 无盘服务器 显卡,我也来说说网吧配机器该用什么显卡
- 离谱的 CSS!从表盘刻度到剪纸艺术
- 运放放大倍数计算公式_放大器设计100问
- C++八股文分享---数据结构其二---哈希表
- Python——文件与IO
- 基于CSS和HTML技术开发中国海洋大学网站的首页