mysql学习教程参考:https://www.w3school.com.cn/sql/index.asp
where 与 having实例运用参考:https://www.2cto.com/database/201712/706595.html
 
 
--可选认证中至少有一项通过的用户占比,直接计算
select
 count(distinct case when c.auth_type='可选' and c.auth_status in ('已认证', '已过期') then c.user_id end) as pass_cnt
,count(distinct c.user_id) as tot_cnt
,count(distinct case when c.auth_type='可选' and c.auth_status in ('已认证', '已过期') then c.user_id end)/count(distinct c.user_id) per_cnt
from(
 select a.*,ath.auth_item,ath.auth_type,ath.auth_status,ath.auth_suc_time
  from(
   select laf.user_id,laf.main_order_id,laf.loan_apply_submit_time
   from pl_performance_loan_apply_fact laf
   left join pl_customer_basic_info usb on laf.user_id=usb.user_id
   where laf.reborrow_status = '首借' and usb.merchant_no='DuitSayang'
      and date(laf.loan_apply_submit_time)>='2019-08-03' and date(laf.loan_apply_submit_time)<='2019-08-05'
) a
left join pl_customer_auth_info ath on a.user_id = ath.user_id
) c
;
 
 
--找出未通过认证的用户,巧用group by,having 
select a.user_id,a.phone
  from(
   select laf.user_id,laf.main_order_id,laf.loan_apply_submit_time,usb.phone
   from pl_performance_loan_apply_fact laf
   left join pl_customer_basic_info usb on laf.user_id=usb.user_id
   where laf.reborrow_status = '首借' and usb.merchant_no='DuitSayang'
      and date(laf.loan_apply_submit_time)>='2019-08-03' and date(laf.loan_apply_submit_time)<='2019-08-05'
) a
left join pl_customer_auth_info ath on a.user_id = ath.user_id
group by a.user_id,a.phone
having max( case when ath.auth_type='可选' and ath.auth_status in ('已认证', '已过期') then 1 else 0 end) = 0
 
--注册未申请的phone

# 9月注册未申贷用户电话号码

select concat('\'',usb.phone) as phone
from (
select phone, user_id from pl_customer_basic_info
where substr(regist_time,1,7)='2019-09'
) usb
left join pl_performance_loan_apply_fact laf on usb.user_id=laf.user_id
group by usb.phone
having max(case when laf.user_id is not null then 1 else 0 end) = 0
;

 
 

巧用having的更多相关文章

  1. [MySQL性能优化系列]巧用索引

    1. 普通青年的索引使用方式 假设我们有一个用户表 tb_user,内容如下: name age sex jack 22 男 rose 21 女 tom 20 男 ... ... ... 执行SQL语 ...

  2. [ACM训练] ACM中巧用文件的输入输出来改写acm程序的输入输出 + ACM中八大输入输出格式

    ACM中巧用文件的输入输出来改写acm程序的输入输出 经常有见大神们使用文件来代替ACM程序中的IO,尤其是当程序IO比较复杂时,可以使自己能够更专注于代码的测试,而不是怎样敲输入. C/C++代码中 ...

  3. TSql 巧用Alt 键

    1,查看表的信息 在TSql 编辑器中,选中一个表,如图 点击Alt+F1,就可以查看表的属性定义 2,使用alt批量插入逗号 在Tsql中使用 in 子句,在(value_List)列表中,经常有很 ...

  4. 前端工程师技能之photoshop巧用系列第三篇——切图篇

    × 目录 [1]切图信息 [2]切图步骤 [3]实战 前面的话 前端工程师除了使用photoshop进行测量之外,更重要的是要使用该软件进行切图.本文是photoshop巧用系列的第三篇——切图篇 切 ...

  5. 前端工程师技能之photoshop巧用系列第二篇——测量篇

    × 目录 [1]测量信息 [2]实战 [3]注意事项 前面的话 前端工程师使用photoshop进行的大量工作实际上是测量.本文是photoshop巧用系列第二篇——测量篇 测量信息 在网页制作中需要 ...

  6. 前端工程师技能之photoshop巧用系列第一篇——准备篇

    × 目录 [1]作用 [2]初始化 [3]常用工具[4]快捷键 前面的话 photoshop是前端工程师无法回避的一个软件,这个软件本身很强大,但我们仅仅需要通过这个工具来完成基本的切图工作即可.本文 ...

  7. 巧用CSS实现分隔线

    下面是几种简单实现分隔线的方法,个人比较喜欢第二种,我也给出了最后第五种比较2的写法,请大家拍砖,或者提供其他好的方法. 单个标签实现分隔线: 点此查看实例展示 .demo_line_01{ padd ...

  8. iOS开发之巧用Block和代理方法结合来传值

    好久没写技术博客了,因为996的工作周期已经持续好几个月了.每天晚上回家都没有太多精力学习很多其他的东西,而且很多时候是接着完善工作的项目的模块开发.所以博客停歇了这么久,更新率也低了不少,今天补充一 ...

  9. jquery 巧用json传参

    JavaScript代码,巧用JSON传参数function AddComment(content) { var comment = {}; comment.threadId = $("#s ...

  10. 在Sqlserver下巧用行列转换日期的数据统计

    在Sqlserver下巧用行列转换日期的数据统计 前言 在SQLSERVER 中有很多统计函数的基础语法,有使用Group By 或 partition by 后配合Sum,Count(*) 等用法. ...

随机推荐

  1. 控制变量行业年份回归时在STATA里怎么操作_stata 分年份回归

    控制变量行业年份回归时在STATA里怎么操作_stata 分年份回归 我希望做一个多元回归,但需要控制年份和行业. (1)年份有7年2006-2012,听说STATA可以自动设置虚拟变量,请问命令是怎 ...

  2. PAT甲级——A1119 Pre- and Post-order Traversals【30】

    Suppose that all the keys in a binary tree are distinct positive integers. A unique binary tree can ...

  3. 第二篇:怕碰到是因为没掌握,来吧,zTree!

    一直以来看见web项目中的树就头疼.这次又给碰上了,什么也别说,这次自己整理一个版本出来实践一下.zTree v3.2的API界面非常清爽,但是在查看API之前,你需要自己先实践一下,知道基本的概念和 ...

  4. 12-6-上下文this

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  5. 解决Eclipse建立Maven Web项目后找不到src/main/java资源文件夹的办法

    问题如题,明细见下图: 解决方法: 在项目上右键选择properties,然后点击java build path,在Librarys下,编辑JRE System Library,选择workspace ...

  6. QVaraint类

    一.QVaraint简介     QVaraint类作为一个包含了大多数Qt普通类型的的联合体类.因为c++联合体没有构造函数和析构函数的,许多继承的Qt类不能够在联合体当中使用.(联合体当中的变量共 ...

  7. idea-----idea的项目中output框出现乱码

    找到tomcat的安装目录中的logging.properties 我的在这里:E:\tools\tomcat\apache-tomcat-8.5.38\conf 改其中的参数 修改前  java.u ...

  8. Entity Framework 学习记录

    msdn  :https://msdn.microsoft.com/zh-cn/data/ee712907.aspx code first 入门: https://msdn.microsoft.com ...

  9. Linux的CentOS上如何安装nginx

    1. 安装nginx前,首先要装好gcc和g++环境: 2. 在centOS上装nginx,需要PCRE.zlib和ssl的支持,出ssl外其他都需要从其官网上下载好,上传至服务器: 3. 接着将上传 ...

  10. Android之GridLayout网格布局

    1.相关属性 GridLayout网格布局是4.0之后引入的布局方式! android:columnCount="4" //设置列数(4列) android:rowCount=&q ...