zoukankan      html  css  js  c++  java
  • 集客业务SQL Mr

    1.各类别客户数:

    SELECT t.客户级别, count(t.客户级别)
    FROM RMW2.IRMS4PORTAL t
    where t.客户级别 in('B类','A类','D类')
    group by 客户级别
    union
    SELECT
    'C类',
    count(*)
    FROM RMW2.IRMS4PORTAL t
    where t.客户级别 in('C -规模客户','C','C类')
    

    2.各类业务客户数  

    SELECT t.包含业务, count(t.包含业务)
    FROM RMW2.IRMS4PORTAL t
    where t.包含业务 in('传输专线','互联网专线','语音专线')
    group by 包含业务
    union
    select 'GPRS专线' ,count(*) 
    from RMW2.IRMS4PORTAL 
    where 包含业务 in('GPRS专线','GPRS')
    


    3.各类别客户总数增长量环比
    上月增长量(取上月新产生的注册客户)

    select t.包含业务,count(t.包含业务) from RMW2.IRMS4PORTAL t  
    where t.包含业务 in('传输专线','互联网专线','语音专线','短信')
    and trunc(t.客户创建时间,'mm') >=trunc(add_months(sysdate,-1),'MM') 
    and  trunc(t.客户创建时间,'mm')<trunc(sysdate,'mm')
    group by t.包含业务
    union
    select 'GPRS专线' ,count(*) 
    from RMW2.IRMS4PORTAL 
    where 包含业务 in('GPRS专线','GPRS')
    and trunc(客户创建时间,'mm')>=trunc(add_months(sysdate,-1),'MM') 
    and  trunc(客户创建时间,'mm')<trunc(sysdate,'mm')
    

    本月增长量(取月初到今日产生的注册用户)
    本月增长量:

    select t.包含业务,count(t.包含业务) from RMW2.IRMS4PORTAL t  
    where t.包含业务 in('传输专线','互联网专线','语音专线','短信')
    and trunc(t.客户创建时间,'mm') >=trunc(sysdate,'mm')
    and  trunc(t.客户创建时间,'mm')<trunc(sysdate,'dd')
    group by t.包含业务
    union
    select 'GPRS专线' ,count(*) 
    from RMW2.IRMS4PORTAL 
    where 包含业务 in('GPRS专线','GPRS')
    and trunc(客户创建时间,'mm')>=trunc(sysdate,'mm')
    and  trunc(客户创建时间,'mm')<trunc(sysdate,'dd')

    将两个表数据合并到一个视图中:

    select m.包含业务,m.上月数据,n.本月数据 from (select t.包含业务,count(t.包含业务)as 上月数据 from RMW2.IRMS4PORTAL t  
    where t.包含业务 in('传输专线','互联网专线','语音专线','短信')
    and trunc(t.客户创建时间,'mm') >=trunc(add_months(sysdate,-1),'MM') 
    and  trunc(t.客户创建时间,'mm')<trunc(sysdate,'mm')
    group by t.包含业务
    union
    select 'GPRS专线' ,count(*) 
    from RMW2.IRMS4PORTAL 
    where 包含业务 in('GPRS专线','GPRS')
    and trunc(客户创建时间,'mm')>=trunc(add_months(sysdate,-1),'MM') 
    and  trunc(客户创建时间,'mm')<trunc(sysdate,'mm'))m
    LEFT OUTER JOIN
    (select t.包含业务,count(t.包含业务)as 本月数据 from RMW2.IRMS4PORTAL t  
    where t.包含业务 in('传输专线','互联网专线','语音专线','短信')
    and trunc(t.客户创建时间,'mm') >=trunc(sysdate,'mm')
    and  trunc(t.客户创建时间,'mm')<trunc(sysdate,'dd')
    group by t.包含业务
    union
    select 'GPRS专线' ,count(*) 
    from RMW2.IRMS4PORTAL 
    where 包含业务 in('GPRS专线','GPRS')
    and trunc(客户创建时间,'mm')>=trunc(sysdate,'mm')
    and  trunc(客户创建时间,'mm')<trunc(sysdate,'dd'))n
    on m.包含业务= n.包含业务
    

    4.上月增长量(取上月新产生的注册客户)

    select t.客户级别,count(t.客户级别) from RMW2.IRMS4PORTAL t  
    where t.客户级别 in('A类','B类','D类')
    and trunc(t.客户创建时间,'mm')<=trunc(add_months(sysdate,-1),'MM') 
    and  trunc(t.客户创建时间,'mm')>trunc(sysdate,'mm')
    group by t.客户级别
    union
    select 'C类',count(*) from RMW2.IRMS4PORTAL
    where 客户级别 in('C','C类','C -规模客户')
    and trunc(客户创建时间,'mm')<=trunc(add_months(sysdate,-1),'MM') 
    and  trunc(客户创建时间,'mm')>trunc(sysdate,'mm')
    

     

    本月增长量(取月初到今日产生的注册用户)
    本月增长量:

    select t.客户级别,count(t.客户级别) from RMW2.IRMS4PORTAL t  
    where t.客户级别 in('A类','B类','D类')
    and trunc(t.客户创建时间,'mm')<=trunc(sysdate,'mm') 
    and  trunc(t.客户创建时间,'mm')>trunc(sysdate,'dd')
    group by t.客户级别
    union
    select 'C类',count(*) from RMW2.IRMS4PORTAL
    where 客户级别 in('C','C类','C -规模客户')
    and trunc(客户创建时间,'mm')<=trunc(sysdate,'mm') 
    and  trunc(客户创建时间,'mm')>trunc(sysdate,'dd')
    

    结果视图合并

    select m.客户级别, m.上月数据, n.本月数据
    from (select t.客户级别, count(t.客户级别) as 上月数据
    from RMW2.IRMS4PORTAL t
    where t.客户级别 in ('B类','A类','D类')
    and trunc(t.客户创建时间, 'mm') >= trunc(add_months(sysdate, -1), 'MM')
    and trunc(t.客户创建时间, 'mm') < trunc(sysdate, 'mm')
    group by t.客户级别
    union
    select 'C类', count(*)
    from RMW2.IRMS4PORTAL
    where 客户级别 in ('C -规模客户','C','C类')
    and trunc(客户创建时间, 'mm') >= trunc(add_months(sysdate, -1), 'MM')
    and trunc(客户创建时间, 'mm') < trunc(sysdate, 'mm')) m
    LEFT OUTER JOIN (select t.客户级别, count(t.客户级别) as 本月数据
    from RMW2.IRMS4PORTAL t
    where t.客户级别 in ('B类','A类','D类')
    and trunc(t.客户创建时间, 'mm') >= trunc(sysdate, 'mm')
    and trunc(t.客户创建时间, 'mm') < trunc(sysdate, 'dd')
    group by t.客户级别
    union
    select 'C类', count(*)
    from RMW2.IRMS4PORTAL
    where 客户级别 in ('C -规模客户','C','C类')
    and trunc(客户创建时间, 'mm') >= trunc(sysdate, 'mm')
    and trunc(客户创建时间, 'mm') < trunc(sysdate, 'dd')) n 
    on m.客户级别 = n.客户级别
    

    5.12个月全省集团客户数量增长趋势

    客户总量

     select to_char(sysdate,'mm')||'月' 月份 ,count(t.客户创建时间) as 客户数量 
     from RMW2.IRMS4PORTAL t where  trunc(t.客户创建时间,'mm')<trunc(sysdate,'mm')
     union
      select to_char(add_months(sysdate,-1),'MM')||'月' 月份 ,count(t.客户创建时间) as 客户数量 
     from RMW2.IRMS4PORTAL t where  trunc(t.客户创建时间,'mm')<trunc(add_months(sysdate,-1),'MM')
      union
      select to_char(add_months(sysdate,-2),'MM')||'月' 月份 ,count(t.客户创建时间) as 客户数量 
     from RMW2.IRMS4PORTAL t where  trunc(t.客户创建时间,'mm')<trunc(add_months(sysdate,-2),'MM')
      union
      select to_char(add_months(sysdate,-3),'MM')||'月' 月份 ,count(t.客户创建时间) as 客户数量 
     from RMW2.IRMS4PORTAL t where  trunc(t.客户创建时间,'mm')<trunc(add_months(sysdate,-3),'MM')
      union
      select to_char(add_months(sysdate,-4),'MM')||'月' 月份 ,count(t.客户创建时间) as 客户数量 
     from RMW2.IRMS4PORTAL t where  trunc(t.客户创建时间,'mm')<trunc(add_months(sysdate,-4),'MM')
      union
      select to_char(add_months(sysdate,-5),'MM')||'月' 月份 ,count(t.客户创建时间) as 客户数量 
     from RMW2.IRMS4PORTAL t where  trunc(t.客户创建时间,'mm')<trunc(add_months(sysdate,-5),'MM')
      union
      select to_char(add_months(sysdate,-6),'MM')||'月' 月份 ,count(t.客户创建时间) as 客户数量 
     from RMW2.IRMS4PORTAL t where  trunc(t.客户创建时间,'mm')<trunc(add_months(sysdate,-6),'MM')
      union
      select to_char(add_months(sysdate,-7),'MM')||'月' 月份 ,count(t.客户创建时间) as 客户数量 
     from RMW2.IRMS4PORTAL t where  trunc(t.客户创建时间,'mm')<trunc(add_months(sysdate,-7),'MM')
      union
      select to_char(add_months(sysdate,-8),'MM')||'月' 月份 ,count(t.客户创建时间) as 客户数量 
     from RMW2.IRMS4PORTAL t where  trunc(t.客户创建时间,'mm')<trunc(add_months(sysdate,-8),'MM')
      union
      select to_char(add_months(sysdate,-9),'MM')||'月' 月份 ,count(t.客户创建时间) as 客户数量 
     from RMW2.IRMS4PORTAL t where  trunc(t.客户创建时间,'mm')<trunc(add_months(sysdate,-9),'MM')
      union
      select to_char(add_months(sysdate,-10),'MM')||'月' 月份 ,count(t.客户创建时间) as 客户数量 
     from RMW2.IRMS4PORTAL t where  trunc(t.客户创建时间,'mm')<trunc(add_months(sysdate,-10),'MM')
      union
      select to_char(add_months(sysdate,-11),'MM')||'月' 月份 ,count(t.客户创建时间) as 客户数量 
     from RMW2.IRMS4PORTAL t where  trunc(t.客户创建时间,'mm')<trunc(add_months(sysdate,-11),'MM')
     
    

    客户增长量:

    select (a.月份 || '月') 月份, b.客户数量
    from (select rownum 月份 FROM DUAL CONNECT BY ROWNUM <= 12) a
    left join (select to_char(t.客户创建时间, 'mm') 月份,
                              count(客户创建时间) 客户数量
                         from RMW2.IRMS4PORTAL t
                        where trunc(t.客户创建时间,'mm')<trunc(sysdate,'mm')
                        and trunc(t.客户创建时间,'mm')>trunc(add_months(sysdate,-12),'MM')
                        group by to_char(t.客户创建时间, 'mm'))  b
      on a.月份 = b.月份
      order by a.月份
    

    6.前12个月产生业务的集团客户用户数趋势

     select (a.月份 || '月') 月份, b.客户数量
      from (select rownum 月份 FROM DUAL CONNECT BY ROWNUM <= 12) a
      left join (select to_char(t.客户创建时间, 'mm') 月份,
                                count(业务创建时间) 客户数量
                           from RMW2.IRMS4PORTAL t
                          where trunc(t.客户创建时间,'mm')<trunc(sysdate,'mm')
                          and trunc(t.客户创建时间,'mm')>trunc(add_months(sysdate,-12),'MM')
                          group by to_char(t.客户创建时间, 'mm'))  b
        on a.月份 = b.月份
     order by a.月份
    

    7.各城市各级别集团客户数

    select 
    m.所属地市,
    SUM(decode(客户级别,'A类',客户数,0)) A类,
    SUM(decode(客户级别,'B类',客户数,0)) B类,
    SUM(decode(客户级别,'C类',客户数,0)) C类,
    SUM(decode(客户级别,'D类',客户数,0)) D类
    from
    (select t.所属地市 ,
    t.客户级别 ,count(*) as 客户数
    from   RMW2.IRMS4PORTAL  t
    group by t.所属地市,t.客户级别)m
    GROUP BY m.所属地市
    
    交谈中请勿轻信汇款、中奖信息、陌生电话,勿使用外挂软件。
    
    ≡z.  21:57:18
    
    select (a.rq || '月') 月份, b.客户数量
     from 
     (select to_number(to_char(add_months(sysdate,rownum-12), 'mm' )) rq,月份
        from (select rownum 月份 FROM DUAL CONNECT BY ROWNUM <= 12 ))
     a
     left join (select to_char(t.客户创建时间, 'mm') 月份,
                               count(业务创建时间) 客户数量
                          from RMW2.IRMS4PORTAL t
                         where trunc(t.客户创建时间,'mm')<trunc(sysdate,'mm')
                         and trunc(t.客户创建时间,'mm')>trunc(add_months(sysdate,-12),'MM')
                         group by to_char(t.客户创建时间, 'mm')
                         )  b
       on a.rq = b.月份
       order by a.月份
    
    ≡z.  22:41:11
    select m.月份, m.客户总量, n.客户增长量 from
    (select (a.rq || '月') 月份, b.客户数量 as 客户总量
    from (select to_number(to_char(add_months(sysdate,rownum-12), 'mm' )) rq,月份
        from (select rownum 月份 FROM DUAL CONNECT BY ROWNUM <= 12 ))
     a
    left join (select to_char(t.客户创建时间, 'mm') 月份,
                               count(业务创建时间) 客户数量
                          from RMW2.IRMS4PORTAL t
                         where trunc(t.客户创建时间,'mm')<trunc(sysdate,'mm')
                         and trunc(t.客户创建时间,'mm')>trunc(add_months(sysdate,-12),'MM')
                         group by to_char(t.客户创建时间, 'mm'))   b
    on a.rq = b.月份
       order by a.月份)m
       
    LEFT OUTER JOIN
       
     ( select to_number(substr( x.月份, 6,2 ))|| '月' as 月份 ,x.客户数量 as 客户增长量  from 
    (select to_char(sysdate,'yyyy-mm')||'月' 月份 ,count(t.客户创建时间) as 客户数量 
    from RMW2.IRMS4PORTAL t where  trunc(t.客户创建时间,'mm')<trunc(sysdate,'mm')
    union all
     select to_char(add_months(sysdate,-1),'yyyy-mm')||'月' 月份 ,count(t.客户创建时间) as 客户数量 
    from RMW2.IRMS4PORTAL t where  trunc(t.客户创建时间,'mm')<trunc(add_months(sysdate,-1),'MM')
     union all
     select to_char(add_months(sysdate,-2),'yyyy-mm')||'月' 月份 ,count(t.客户创建时间) as 客户数量 
    from RMW2.IRMS4PORTAL t where  trunc(t.客户创建时间,'mm')<trunc(add_months(sysdate,-2),'MM')
     union all
     select to_char(add_months(sysdate,-3),'yyyy-mm')||'月' 月份 ,count(t.客户创建时间) as 客户数量 
    from RMW2.IRMS4PORTAL t where  trunc(t.客户创建时间,'mm')<trunc(add_months(sysdate,-3),'MM')
     union all
     select to_char(add_months(sysdate,-4),'yyyy-mm')||'月' 月份 ,count(t.客户创建时间) as 客户数量 
    from RMW2.IRMS4PORTAL t where  trunc(t.客户创建时间,'mm')<trunc(add_months(sysdate,-4),'MM')
     union all
     select to_char(add_months(sysdate,-5),'yyyy-mm')||'月' 月份 ,count(t.客户创建时间) as 客户数量 
    from RMW2.IRMS4PORTAL t where  trunc(t.客户创建时间,'mm')<trunc(add_months(sysdate,-5),'MM')
     union  all
     select to_char(add_months(sysdate,-6),'yyyy-mm')||'月' 月份 ,count(t.客户创建时间) as 客户数量 
    from RMW2.IRMS4PORTAL t where  trunc(t.客户创建时间,'mm')<trunc(add_months(sysdate,-6),'MM')
     union
     select to_char(add_months(sysdate,-7),'yyyy-mm')||'月' 月份 ,count(t.客户创建时间) as 客户数量 
    from RMW2.IRMS4PORTAL t where  trunc(t.客户创建时间,'mm')<trunc(add_months(sysdate,-7),'MM')
     union all
     select to_char(add_months(sysdate,-8),'yyyy-mm')||'月' 月份 ,count(t.客户创建时间) as 客户数量 
    from RMW2.IRMS4PORTAL t where  trunc(t.客户创建时间,'mm')<trunc(add_months(sysdate,-8),'MM')
     union all
     select to_char(add_months(sysdate,-9),'yyyy-mm')||'月' 月份 ,count(t.客户创建时间) as 客户数量 
    from RMW2.IRMS4PORTAL t where  trunc(t.客户创建时间,'mm')<trunc(add_months(sysdate,-9),'MM')
     union all
     select to_char(add_months(sysdate,-10),'yyyy-mm')||'月' 月份 ,count(t.客户创建时间) as 客户数量 
    from RMW2.IRMS4PORTAL t where  trunc(t.客户创建时间,'mm')<trunc(add_months(sysdate,-10),'MM')
     union all
     select to_char(add_months(sysdate,-11),'yyyy-mm')||'月' 月份 ,count(t.客户创建时间) as 客户数量 
    from RMW2.IRMS4PORTAL t where  trunc(t.客户创建时间,'mm')<trunc(add_months(sysdate,-11),'MM'))x
    order by x.月份
    )n
       
       on m.月份 = n.月份
       
       
       
    ≡z.  22:52:50
    select 客户名称,count(包含业务)
    from 
    RMW2.IRMS4PORTAL
    group by 客户名称
    select 客户名称,count(包含业务) as 客户用户数
    from 
    RMW2.IRMS4PORTAL
    group by 客户名称
    

      

      

      

      

        

    Mr-sniper
    北京市海淀区
    邮箱:rafx_z@hotmail.com
  • 相关阅读:
    定制自己的PHP语法-在PHP中实现unless
    欢迎使用CSDN-markdown编辑器
    在 Laravel 中通过 Artisan View 扩展包创建及删除应用视图文件
    直接可用的loading.js
    vue后退判断是否有历史记录,有就返回上一级,否则返回指定路由
    js防抖和节流
    IE增加Meta标签(IE=Edge,chrome=1)兼容IE问题
    如何覆盖 node_modules 里的文件
    js运行代码计时器
    vue打包font字体文件路径错误的问题处理
  • 原文地址:https://www.cnblogs.com/rafx/p/2679220.html
Copyright © 2011-2022 走看看