转载自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. 廖雪峰Java13网络编程-1Socket编程-1网络编程概念

    1.计算机网络 1.1 什么是计算机网络? 两台或更多计算机组成的网络 同一网络内的任意2台计算机都可以直接通信 所有计算机必须遵循同一种网络协议 1.2 什么是互联网 互联网是网络的网络 互联网采用 ...

  2. watchbog再升级,企业黄金修补期不断缩小,或面临蠕虫和恶意攻击

    概要 近日,阿里云安全团队发现wacthbo挖矿团伙[1]新增了CVE_2019_5475 的漏洞利用代码,并开始进行尝试性攻击.通过对CVE_2019_5475漏洞的生命周期进行分析后发现,漏洞批量 ...

  3. 使用应用程序(Java/Python)访问MaxCompute Lightning进行数据开发

    MaxCompute Lightning是MaxCompute产品的交互式查询服务,支持以PostgreSQL协议及语法连接访问Maxcompute项目,让您使用熟悉的工具以标准 SQL查询分析Max ...

  4. js获取base64格式图片预览上传并用php保存到本地服务器指定文件夹

    html: <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF ...

  5. 你知道的和不知道的sass

    关于sass,大多数人的认识一个写css的工具而已 其实就是的 但是这个工具的威力你发挥了多少呢... 以下全部都是干货,希望你能用在自己的项目里 定义集合 我们通常是这么定义变量的 $warning ...

  6. safari跨域cookie的问题

    最近做了一个项目,是将自己公司的H5页面嵌入到其他公司的pc和移动端,采用的方案是iframe,跨域数据传输用的postMessage,最后在联调过程中发现iPhone的微信中无法打开,在 Setti ...

  7. 基于知识图谱的APT组织追踪治理

    高级持续性威胁(APT)正日益成为针对政府和企业重要资产的不可忽视的网络空间重大威胁.由于APT攻击往往具有明确的攻击意图,并且其攻击手段具备极高的隐蔽性和潜伏性,传统的网络检测手段通常无法有效对其进 ...

  8. LinkedList集合 实现栈和队列

    LinkedList集合的底层是链表结构实现的,所以可以模拟栈(先进后出)和队列(先进先出). 方法: addFirst() //添加元素到列表的起始位置 addLast() //添加元素到列表的结束 ...

  9. Odoo(OpenERP)配置文件详解

    [options] ; addons模块的查找路径 addons_path = E:\GreenOdoo8.0\source\openerp\addons ; 管理员主控密码(用于创建.还原和备份数据 ...

  10. [JSOI2010]连通数 (dfs或tarjan或bitset)+bitset学习

    题目描述 输入格式 输入数据第一行是图顶点的数量,一个正整数N. 接下来N行,每行N个字符.第i行第j列的1表示顶点i到j有边,0则表示无边. 输出格式 输出一行一个整数,表示该图的连通数. 样例 样 ...