转载自https://blog.csdn.net/qq_27922171/article/details/86477544

同类别自动生成序列号:https://bbs.csdn.net/topics/392035580?locationNum=3&fps=1

--累计放款额度及件均用时
select
    hou.time as '时间段'
    ,isu.accum_loan_contract_amt as '累计放款额度'
    ,round(isu.issue_cost_time / isu.issue_finish_cnt) as '放款流程用时'
from dim_hour hou
left join (
    select
        isu.loan_contract_amt
        ,isu.issue_finish_cnt
        ,coalesce(isu.issue_cost_time,0) as issue_cost_time
        ,case
            when @time is null then @accum_loan_contract_amt:=isu.loan_contract_amt
            else @accum_loan_contract_amt:=@accum_loan_contract_amt + isu.loan_contract_amt
  end as accum_loan_contract_amt
        ,@time:=isu.time as time
    from (select @time:=null, @accum_loan_contract_amt:=null)s,
 (
        select
            hou.time
            ,sum(case when date(isu.loan_issue_time) = curdate() then isu.loan_contract_amt else 0 end) as loan_contract_amt
            ,count(case when date(coalesce(isu.loan_issue_time,isu.loan_issue_fail_time)) = curdate() then isu.split_order_id else null end) as issue_finish_cnt
            ,sum(case
                 when date(coalesce(isu.loan_issue_time,isu.loan_issue_fail_time)) = curdate()
                     then timestampdiff(second,isu.loan_issue_submit_time, coalesce(isu.loan_issue_time,isu.loan_issue_fail_time))
                 else null end) as issue_cost_time
        from dim_hour hou
        left join (
            SELECT * from pl_performance_loan_apply_fact where date(coalesce(loan_issue_time,loan_issue_fail_time)) = curdate()
        )isu on DATE_FORMAT(isu.loan_issue_time, '%H:%i:%s') >= hou.`time` and DATE_FORMAT(isu.loan_issue_time, '%H:%i:%s') < hou.due_time
        join (select time from dim_hour where start_time <= DATE_FORMAT(now() , '%H:%i:%s') and DATE_FORMAT(now(), '%H:%i:%s') < end_time) dim on hou.time <= dim.time
        group by hou.time
        order by hou.time
    )isu
)isu on isu.time = hou.time
;
 
 
--工作时间,不分类生成序列号
SELECT  tot.collect_user_name AS `催收员`, sum(tot.collect_diff)/3600 AS `工作时间`
FROM
(
SELECT tot.collect_user_name
, CASE WHEN TIMESTAMPDIFF(SECOND, par.`collect_time`, tot.`collect_time`) > 1800 THEN NULL ELSE TIMESTAMPDIFF(SECOND, par.`collect_time`, tot.`collect_time`) END AS collect_diff
FROM
(
SELECT tot.*,  @collect_series:= @collect_series + 1 AS collect_series  
FROM ( 
    SELECT collect_user_name, collect_time FROM pl_collect_call_info cat
   
    ORDER BY collect_user_name, collect_time
) tot, ( SELECT @collect_series:=-1 )s
) tot
LEFT JOIN (
SELECT tot.*,  @collect_series_2:= @collect_series_2 + 1 AS collect_series_2    
FROM ( 
    SELECT collect_user_name, collect_time FROM pl_collect_call_info cat
    ORDER BY collect_user_name, collect_time
) tot, ( SELECT  @collect_series_2:=0 )s
) par ON tot.collect_series = par.collect_series_2 AND par.`collect_user_name` = tot.`collect_user_name`
WHERE par.collect_user_name IS NOT NULL
) tot
GROUP BY tot.collect_user_name
;
 
--工作时间,方法2,分类生成序列号
SELECT collect_user_name, collect_time,NO
FROM
(
SELECT t.*,
       CASE WHEN @partition_by = t.collect_user_name THEN @rownum := @rownum + 1
            ELSE @rownum :=1
       END AS NO,
       @partition_by := t.collect_user_name AS partition_by
FROM ( 
    SELECT collect_user_name, collect_time FROM pl_collect_call_info cat
    WHERE  date(cat.collect_time) = curdate()
                     
    #ORDER BY collect_user_name, collect_time
) t
INNER JOIN (SELECT @rownum :=0) r
        ON 1=1
INNER JOIN (SELECT @partition_by :='') p
        ON 1=1
ORDER BY t.collect_user_name, t.collect_time
)tb
;
 
--注册人数分布(时间段),按时间分类
SELECT
    sls.time as `时间段`
    ,case when sls.time > hou.time then null else sls.cust_cnt          end as `分段注册人数`
    ,case when sls.time > hou.time then null else sls.accum_cust_cnt    end as `累计注册人数`
from (
    select
        dtl.cust_cnt #as `分段注册人数`
        ,case
            when @time is null then @accum_cust_cnt:=dtl.cust_cnt
            else @accum_cust_cnt:=@accum_cust_cnt + dtl.cust_cnt end
            as accum_cust_cnt #`累计注册人数`
        ,@time:=dtl.time as time #`时间段`
    from (select @time:=null, @accum_cust_cnt:=null)s, (
        select
            hou.time
            ,count(distinct usb.user_id) as cust_cnt
        from dim_hour hou
        left join (
            select usb.user_id,usb.regist_time from pl_customer_basic_info usb
            where date(usb.regist_time) = curdate() 
        )usb on DATE_FORMAT(usb.regist_time, '%H:%i:%s') >= hou.`time` and DATE_FORMAT(usb.regist_time, '%H:%i:%s') < hou.due_time
        group by hou.time
        order by hou.time
    )dtl
)sls
left join (
    select * from dim_hour
    where start_time <= DATE_FORMAT(now(), '%H:%i:%s')
        and DATE_FORMAT(now(), '%H:%i:%s') < end_time
) hou on 1=1
;
--注册人数分布(时间段),按公司、马甲、时间分类
SELECT cpy.company
    ,sls.merchant_no
    ,sls.time as period
    ,case when sls.time > hou.time then null else sls.cust_cnt          end as rgs_cnt
    ,case when sls.time > hou.time then null else sls.accum_cust_cnt    end as accum_rgs_cnt
from (
    select dtl.time
        ,dtl.cust_cnt #as `分段注册人数`
        ,CASE
WHEN @merchant_no IS NULL THEN @accum_cust_cnt:=dtl.cust_cnt
WHEN @merchant_no != merchant_no2 THEN @accum_cust_cnt:=dtl.cust_cnt
ELSE @accum_cust_cnt:=@accum_cust_cnt + dtl.cust_cnt END
AS accum_cust_cnt #`累计注册人数`
        ,@merchant_no:=dtl.merchant_no2 as merchant_no #`时间段`
    from (select @merchant_no:=null, @accum_cust_cnt:=null)s, (
        select
            hou.time,usb.merchant_no,usb.merchant_no2
            ,count(distinct usb.user_id) as cust_cnt
        from dim_hour hou
        left join (
            select usb.user_id,usb.regist_time ,usb.merchant_no,usb.merchant_no as merchant_no2
   from (select * from pl_customer_basic_info usb where date(usb.regist_time) = curdate()) usb
            left join dim_company_app cpy on usb.merchant_no=cpy.merchant_no
        )usb on DATE_FORMAT(usb.regist_time, '%H:%i:%s') >= hou.`time` and DATE_FORMAT(usb.regist_time, '%H:%i:%s') < hou.due_time
        group by hou.time,usb.merchant_no,merchant_no2
        order by usb.merchant_no,hou.time
    )dtl
)sls
left join (
    select * from dim_hour
    where start_time <= DATE_FORMAT(now(), '%H:%i:%s')
        and DATE_FORMAT(now(), '%H:%i:%s') < end_time
) hou on 1=1
left join dim_company_app cpy on sls.merchant_no=cpy.merchant_no
where sls.merchant_no is not null
order by merchant_no,period
;
 
--累计放款额度,按时间分类
select
    hou.time as '时间段'
    ,isu.accum_loan_contract_amt as '累计放款额度'
    ,round(isu.issue_cost_time / isu.issue_finish_cnt) as '放款流程用时'
    ,round(isu.issue_cost_time_v2 / isu.issue_finish_cnt) as '放款流程用时v2'
from dim_hour hou
left join (
    select
        isu.loan_contract_amt
        ,isu.issue_finish_cnt
        ,coalesce(isu.issue_cost_time,0) as issue_cost_time
        ,case
            when @time is null then @accum_loan_contract_amt:=isu.loan_contract_amt
            else @accum_loan_contract_amt:=@accum_loan_contract_amt + isu.loan_contract_amt end
             as accum_loan_contract_amt
        ,coalesce(isu.issue_cost_time_v2,0) as issue_cost_time_v2
        ,@time:=isu.time as time
    from (select @time:=null, @accum_loan_contract_amt:=null)s, (
        select
            hou.time
            ,sum(case when date(isu.loan_issue_time) = curdate() then isu.loan_contract_amt else 0 end) as loan_contract_amt
            ,count(case when date(isu.loan_issue_submit_time) = curdate() then isu.split_order_id else null end) as issue_finish_cnt
            ,sum(case
                 when date(coalesce(isu.loan_issue_time,isu.loan_issue_fail_time)) = curdate()
                     then timestampdiff(second,isu.loan_issue_submit_time, coalesce(isu.loan_issue_time,isu.loan_issue_fail_time))
                 else null end) as issue_cost_time
             ,sum(case
                 when date(coalesce(isu.loan_issue_time,isu.loan_issue_fail_time)) = curdate()
                     then timestampdiff(second,isu.loan_issue_submit_time, coalesce(isu.loan_issue_time,isu.loan_issue_fail_time))
             when date(isu.loan_issue_submit_time)= curdate() and isu.loan_issue_time is null and isu.loan_issue_fail_time is null
                 then timestampdiff(second,isu.loan_issue_submit_time, now())
                 else null end) as issue_cost_time_v2
        from dim_hour hou
        left join (
            SELECT * from pl_performance_loan_apply_fact where date(coalesce(loan_issue_time,loan_issue_fail_time)) = curdate()
        )isu on DATE_FORMAT(isu.loan_issue_time, '%H:%i:%s') >= hou.`time` and DATE_FORMAT(isu.loan_issue_time, '%H:%i:%s') < hou.due_time
        join (select time from dim_hour where start_time <= DATE_FORMAT(now() , '%H:%i:%s') and DATE_FORMAT(now(), '%H:%i:%s') < end_time) dim on hou.time <= dim.time
        group by hou.time
        order by hou.time
    )isu
)isu on isu.time = hou.time
;
 
--累计放款额度,按公司、时间分类
select isu.company
    ,hou.time
 ,isu.loan_contract_amt
 ,isu.accum_loan_contract_amt
    ,isu.issue_cost_time
    ,isu.issue_cost_time_v2
    ,isu.issue_finish_cnt
from dim_hour hou
left join (
    select
        isu.loan_contract_amt
        ,isu.issue_finish_cnt
        ,coalesce(isu.issue_cost_time,0) as issue_cost_time
      
  ,case
      WHEN @company IS NULL THEN @accum_loan_contract_amt:=isu.loan_contract_amt
            WHEN @company != company2 THEN @accum_loan_contract_amt:=isu.loan_contract_amt
            ELSE @accum_loan_contract_amt:=@accum_loan_contract_amt + isu.loan_contract_amt END
            AS accum_loan_contract_amt 
        ,coalesce(isu.issue_cost_time_v2,0) as issue_cost_time_v2
  ,@company:=isu.company2 as company
    ,isu.time  
    from (select @company:=null,@accum_loan_contract_amt:=null)s, (
        select cpy.company,cpy.company as company2
            ,hou.time
            ,sum(case when date(isu.loan_issue_time) = curdate() then isu.loan_contract_amt else 0 end) as loan_contract_amt
            ,count(case when date(isu.loan_issue_submit_time) = curdate() then isu.split_order_id else null end) as issue_finish_cnt
            ,sum(case
                 when date(coalesce(isu.loan_issue_time,isu.loan_issue_fail_time)) = curdate()
                     then timestampdiff(second,isu.loan_issue_submit_time, coalesce(isu.loan_issue_time,isu.loan_issue_fail_time))
                 else null end) as issue_cost_time
             ,sum(case
                 when date(coalesce(isu.loan_issue_time,isu.loan_issue_fail_time)) = curdate()
                     then timestampdiff(second,isu.loan_issue_submit_time, coalesce(isu.loan_issue_time,isu.loan_issue_fail_time))
             when date(isu.loan_issue_submit_time)= curdate() and isu.loan_issue_time is null and isu.loan_issue_fail_time is null
                 then timestampdiff(second,isu.loan_issue_submit_time, now())
                 else null end) as issue_cost_time_v2
        from dim_hour hou
        left join (
            SELECT * from pl_performance_loan_apply_fact where date(coalesce(loan_issue_time,loan_issue_fail_time)) = curdate()
        )isu on DATE_FORMAT(isu.loan_issue_time, '%H:%i:%s') >= hou.`time` and DATE_FORMAT(isu.loan_issue_time, '%H:%i:%s') < hou.due_time
        join (select time from dim_hour where start_time <= DATE_FORMAT(now() , '%H:%i:%s') and DATE_FORMAT(now(), '%H:%i:%s') < end_time) dim on hou.time <= dim.time
  join pl_customer_basic_info usb on isu.user_id=usb.user_id
  join dim_company_app cpy on usb.merchant_no=cpy.merchant_no
        group by cpy.company,hou.time
        order by cpy.company,hou.time
    )isu
)isu on isu.time = hou.time
;

SELECT (@i :=@i + 1)生成序列号的更多相关文章

  1. springMVC使用与生成序列号

    springMVC使用与生成序列号 我是以springMVC的方式提供序列号 代码可以直接在项目中用 第一步:controller类 @Autowired private PkGenerator pk ...

  2. 利用ir.sequence自动生成序列号

    利用ir.sequence自动生成序列号 什么是序列号 可以这么理解,我有一个产品序号,编码的前缀是SOP,后缀是0001~9999的序号,没生成一个产品就自动流水加一,序列号不会重复,odoo中的i ...

  3. SQL Server 怎样生成序列号(虚拟数字辅助表)

    </pre><pre name="code" class="sql">--生成一个"序列" 或者说生成一个" ...

  4. Idea为类生成序列号(十一)

    新建一个测试的实体类Gradle,实现java.io.Serializable接口,选择类名,按Alt+Enter键,出现的提示框中没有生成serialVersionUID的提示,这个需要设置之后才会 ...

  5. 使用Redis的INCR、Hsetnx、Hincrby的命令生成序列号

    Redis INCR命令 用于由一个递增key的整数值.如果该key不存在,它被设置为0执行操作之前.如果key包含了错误类型的值或包含不能被表示为整数,字符串,则返回错误.该操作被限制为64位带符号 ...

  6. mysql查询结果自动生成序列号

  7. .NET平台开源项目速览(9)软件序列号生成组件SoftwareProtector介绍与使用

    在文章:这些.NET开源项目你知道吗?让.NET开源来得更加猛烈些吧!(第二辑)中,给大家初步介绍了一下Software Protector序列号生成组件.今天就通过一篇简单的文章来预览一下其强大的功 ...

  8. 如何用JAVA生成注册序列号

    原文:http://blog.csdn.net/eagleking012/article/details/7099900 平常我们都接触过软件注册,输入序列号.激活码.注册码.授权码:对于这些字符码到 ...

  9. 一个shell脚本给客户使用服务器生成一个序列号

    #!/bin/bash interface=`ls /sys/class/net|grep en|awk 'NR==1{print}'` if [ ! -e /etc/adserver/.seq.in ...

随机推荐

  1. 浅谈response和request方法

    一:概述 Web服务器收到客户端的http请求,会针对每一次请求,分别创建一个用于代表请求的request对象.和代表响应的response对象. 按这个理解的话一次请求生成一个request和res ...

  2. PAT甲级——A1009 Product of Polynomials

    This time, you are supposed to find A×B where A and B are two polynomials. Input Specification: Each ...

  3. Java+微信支付(下预购单+回调+退款+查询账单)

    前言: 现在的APP的离不开微信支付, 现在项目里接入微信支付 , 微信支付的官方文档是:https://pay.weixin.qq.com/wiki/doc/api/app/app.php?chap ...

  4. 01_Spring入门程序

    一.什么是Spring? 1.Spring是分层的JavaSE/EE full-stack(一站式) 轻量级开源框架 2.spring是一个高度灵活的轻量级框架,其目的是降低企业级应用开发的复杂度. ...

  5. Python学习day19-常用模块之re模块

    figure:last-child { margin-bottom: 0.5rem; } #write ol, #write ul { position: relative; } img { max- ...

  6. 04-python 学习第四点-装饰器

    装饰器就是一个函数,他是通过不修改某个函数的源代码和调用方式的前提下可以添加新功能的一种函数.在python 中装饰器一般采用高阶函数和嵌套函数达到装饰的作用,下面进行实例讲解: 1.目前有一个网址有 ...

  7. python3-常用模块之sys

    import syssys 是和Python解释器打交道的sys.argvprint(sys.argv) # argv的第一个参数 是python这个命令后面的值 主要用途 1. 程序员 运维人员 在 ...

  8. <每日一题>题目6:二分查找

    #二分查找 ''' 1.end问题 2.44对应的end<start 找不到情况 3.返回值递归的情况 4,611,aim太大的情况 ''' l = [2,3,5,10,15,16,18,22, ...

  9. redis Hash 命令

    HDEL key field2 [field2] 删除一个或多个哈希表字段 HEXISTS key field 查看哈希表 key 中,指定的字段是否存在. HGET key field 获取存储在哈 ...

  10. Tornado demo3 - tcpecho分析

    在这个demo中,主要是使用了Tornado中异步的TCP client和server来实现一个简单的echo效果(即客户端发送的message会从server端返回到client).代码的githu ...