描述

查询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相关推荐

最新文章

  1. android 多参数,玩转Android monkey之多参数实战
  2. laravel 分词搜索匹配度_SEO除了“中文分词”还有“文本分析”- 搜狗蜘蛛池博客...
  3. tomcat闪退没有报错_Appium在Android平台几种常见报错的解决方案
  4. =空值返回空值_@ParameterizedTest在@CvsSource中具有空值
  5. Android M 新的运行时权限开发者需要知道的一切
  6. AOJ0008 Sum of 4 Integers【暴力】
  7. 驳熊节和Martin Fowler的Java消亡论!
  8. WebDAV被启用(转)
  9. Flume 1.8.0 用户指南(Flume 1.8.0 User Guide)
  10. 【Java算法】Java抽奖算法,适用于各种抽奖
  11. 孙鑫老师的帮助文档 MSDN Library 2001January 下载地址
  12. Qt日历控件显示周数为:日一二三四五六
  13. java 合并多个文件_java中如何将两个文件合并到另一个文件
  14. 天牛须matlab,BAS天牛须搜索优化算法.pdf
  15. 无盘服务器 显卡,我也来说说网吧配机器该用什么显卡
  16. 离谱的 CSS!从表盘刻度到剪纸艺术
  17. 运放放大倍数计算公式_放大器设计100问
  18. C++八股文分享---数据结构其二---哈希表
  19. Python——文件与IO
  20. 基于CSS和HTML技术开发中国海洋大学网站的首页

热门文章

  1. bootstrap modal 弹出效果
  2. 软件工程概论个人作业02
  3. Jquery_操作cookies
  4. 给GridView增加求和行
  5. (拆点+最小路径覆盖) bzoj 2150
  6. 通过 cygwin64 自己编译对应的 Tera Term cyglaunch.exe
  7. Cocos2d-x学习笔记(三十)之 游戏存档
  8. 如何制作风格迁移图?
  9. 【小贴士】在线画流程图工具
  10. TIOBE 6 月榜单: Python 有望超越 C 语言成为第一名