proc 储过程

proc 储过程

SET QUOTED_IDENTIFIER ON 

GO

SET ANSI_NULLS ON 

GO

 

–**分类报表存储过程

ALTER  proc gnfl_proc 

as 

 

declare

 

@p_phone varchar(30), @p_sex int, @p_age int, @p_city varchar(50), @p_r_type int, @p_r_time datetime,

 

   @v_ping     int, –PING码上行总计  

 

   @v_ping_ejj int, –PING码上行其中EJJ用户数

 

   @v_ping_bjj int, –PING码上行其中BJJ用户数

 

   @v_ping_con int, –PING码上行中注册和未注册的用户(consumer)不含发送EJJ/BJJ用户

 

 

 

   @v_ping_reg     int, –发送PING码并注册的用户(含不在同一天注册的用户)

 

   @v_ping_reg_ejj int, –发送PING码并注册且发送过EJJ的用户

 

   @v_ping_reg_bjj int, –发送PING码并注册且发关过BJJ的用户

 

   @v_ping_reg_con int, –发送PING码注册的用户(consumer)不含发送过EJJ/BJJ的用户

 

 

 

   @v_ping_noreg     int, –发送PING码未注册的用户

 

   @v_ping_noreg_ejj int, –发送PING码未注册而且发送了EJJ的用户

 

   @v_ping_noreg_bjj int, –发送PING码未注册而且发送了BJJ的用户

 

   @v_ping_noreg_con int, –发送PING码未注册也示发送EJJ/BJJ的用户(consumer)]

 

 

 

   @v_man    int, –男性

 

   @v_women  int, –女性

 

   @v_age20  int, –年龄在20岁以下

 

   @v_age29  int, –年龄在20~29岁

 

   @v_age39  int, –年龄在29~39岁

 

   @v_age49  int, –年龄在39~49岁

 

   @v_age50  int, –年龄在49岁以上

 

   @v_citysh int, –上海

 

   @v_citybj int, –北京

 

   @v_cityhz int, –杭州

 

   @v_citygz int, –广州

 

   @v_citysz int, –深圳

 

   @v_cityqt int, –其他城市

 

 

 

   @v_ejj_user int, –EJJ用户      1

 

   @v_bjj_user int, –BJJ用户      2

 

 

 

   @v_coun int –写入临时表的判断条件

 

 

select 

–统计男

@v_man=count(

case 

when usersex=’1′ then 1 else null

end

),

–统计女

@v_women=count(

case 

when usersex=’2′ then 1 else null

end

), 

–统计20岁

@v_age20=count(case  

    when userAge< 20  then 1

    else null

    end

    ) ,

–统计29岁

@v_age29=count(case 

    when userAge< 30 and userAge>19 then 1

    else null

    end

    ),

–统计39岁

@v_age39=count(case 

    when userAge < 40 and userAge>29 then 1

    else null

    end),

–统计49岁

@v_age49=count(case 

    when userAge < 50 and userAge>39 then 1

    else null

    end),

–统计50岁

@v_age50=count(case 

    when userAge >49 then 1

    else null

    end),

–统计上海用户

@v_citysh=count(case  

    when city=’上海’  then 1

    else null

    end

    ) ,

–统计广州用户

@v_citygz=count(case  

    when city=’广州’  then 1

    else null

    end

    ),

–统计北京用户

@v_citybj=count(case  

    when city=’北京’  then 1

    else null

    end

    ),

–统计杭州用户

@v_cityhz=count(case  

    when city=’杭州’  then 1

    else null

    end

    ),

–统计深圳用户

@v_citysz=count(case  

    when city=’深圳’  then 1

    else null

    end

    ) ,

 

—-统计除已上之外的其他用户

@v_cityqt=count(case  

    when city not in (‘北京’,’广州’,’上海’,’杭州’,’深圳’)  then 1

    else null

    end

    ) 

from (select *

 

              from tb_gl_userInf

 

             where registertype = 4 

 

               and usertype&4=4

 

               and CONVERT(char(10), registertime,20) =CONVERT(char(10), dateadd(dd,-1,getdate()),20)

 

            union all

 

            select *

 

              from tb_gl_userInf

 

             where registertype !=4 

 

               and usertype&4 = 4

 

               and CONVERT(char(10), mulregtime,20)  = CONVERT(char(10), dateadd(dd,-1,getdate()),20)) a

     

 

  –统计ping码上行数据tb_gl_userreplycommand

 

  –ping码上行总计  

 

  select @v_ping=count(*)

 

    from (select *

 

           from tb_gl_userreplycommand

     

           where motype = 3

 

           and CONVERT(char(10), sendtime,20) =CONVERT(char(10), dateadd(dd,-1,getdate()),20))  a

 

  –发送ping码且发送EJJ用户数

 

  select @v_ping_ejj=count(*)

 

  from (select *

 

        from tb_gl_userreplycommand

 

        where motype = 3

 

        and CONVERT(char(10), sendtime,20) =CONVERT(char(10), dateadd(dd,-1,getdate()),20))  a 

 

    where telephone in

 

        (select telephone from tb_gl_userreplycommand where motype = ‘2’)

 

 

 

  –发送ping码且发送BJJ用户数

 

  select @v_ping_bjj=count(*)

 

    from (select *

 

            from tb_gl_userreplycommand

 

           where motype = 3

 

             and CONVERT(char(10), sendtime,20) =CONVERT(char(10), dateadd(dd,-1,getdate()),20))  a 

 

   where telephone in

 

         (select telephone from tb_gl_userreplycommand where motype = ‘1’);

 

 

 

  –发送ping码且非EJJ/BJJ(consumer)用户

 

   set @v_ping_con=  @v_ping –  @v_ping_ejj –  @v_ping_bjj;

 

 

 

  –发送ping码并注册的用户

 

  select @v_ping_reg=count(distinct telephone)

 

    from (select *

 

            from tb_gl_userreplycommand

 

           where motype = 3

 

             and CONVERT(char(10), sendtime,20) <=CONVERT(char(10), dateadd(dd,-1,getdate()),20)) a 

 

   where telephone in

 

         (select telephone

 

            from tb_gl_userreplycommand

 

           where motype = 4

 

             and CONVERT(char(10), sendtime,20) =CONVERT(char(10), dateadd(dd,-1,getdate()),20))

 

 

 

  –发送ping码并注册且发送过EJJ的用户

 

  select @v_ping_ejj=count(distinct telephone)

 

    from (select *

 

            from tb_gl_userreplycommand

 

           where motype = 3

 

             and CONVERT(char(10), sendtime,20) <=CONVERT(char(10), dateadd(dd,-1,getdate()),20)) a

 

   where telephone in

 

         (select telephone

 

            from tb_gl_userreplycommand

 

           where motype = 4

 

             and CONVERT(char(10), sendtime,20) =CONVERT(char(10), dateadd(dd,-1,getdate()),20)

 

     and telephone in

 

         (select telephone from tb_gl_userreplycommand where motype = ‘2’))

 

 

 

  –发送ping码并注册且发送过BJJ的用户

 

  select @v_ping_reg_bjj=count(distinct telephone)

 

   from (select *

 

            from tb_gl_userreplycommand

 

           where motype = 3

 

             and CONVERT(char(10), sendtime,20) <=CONVERT(char(10), dateadd(dd,-1,getdate()),20)) a

 

   where telephone in

 

         (select telephone

 

            from tb_gl_userreplycommand

 

           where motype = 4

 

             and CONVERT(char(10), sendtime,20) =CONVERT(char(10), dateadd(dd,-1,getdate()),20)

 

     and telephone in

 

         (select telephone from tb_gl_userreplycommand where motype = ‘1’))

 

 

 

  –发送ping码并注册但不含EJJ/BJJ用户(consumer)

   set @v_ping_reg_ejj=0

   set @v_ping_reg_con=  @v_ping_reg –  @v_ping_reg_ejj –  @v_ping_reg_bjj;

 

 

 

  –发送ping码未注册的用户

 

  select @v_ping_noreg=count(distinct telephone)

 

    from (select *

 

            from tb_gl_userreplycommand

 

           where motype = 3

 

             and CONVERT(char(10), sendtime,20) =CONVERT(char(10), dateadd(dd,-1,getdate()),20)) a

 

   where telephone not in

 

         (select telephone

 

            from tb_gl_userreplycommand

 

           where motype = 4

 

             and CONVERT(char(10), sendtime,20) =CONVERT(char(10), dateadd(dd,-1,getdate()),20))

 

 

 

  –发送ping码未注册且发送过EJJ的用户

 

  select @v_ping_noreg_ejj=count(distinct telephone) 

 

    from (select *

 

            from tb_gl_userreplycommand

 

            where motype = 3

 

            and CONVERT(char(10), sendtime,20) =CONVERT(char(10), dateadd(dd,-1,getdate()),20)) a

 

   where telephone in

 

         (select telephone

 

            from tb_gl_userreplycommand

 

           where motype = 4

 

             and CONVERT(char(10), sendtime,20) =CONVERT(char(10), dateadd(dd,-1,getdate()),20)

 

     and telephone in

 

         (select telephone from tb_gl_userreplycommand where motype = ‘2’))

 

 

 

  –发送ping码未注册且发送过BJJ的用户

 

  select @v_ping_noreg_bjj=count(distinct telephone)

 

    from (select *

 

            from tb_gl_userreplycommand

 

           where motype = 3

 

             and CONVERT(char(10), sendtime,20) =CONVERT(char(10), dateadd(dd,-1,getdate()),20)) a

 

   where telephone in

 

         (select telephone

 

            from tb_gl_userreplycommand

 

           where motype = 4

 

             and CONVERT(char(10), sendtime,20) =CONVERT(char(10), dateadd(dd,-1,getdate()),20)

 

     and telephone in

 

         (select telephone from tb_gl_userreplycommand where motype = ‘1’))

 

 

 

  –发送ping码未注册未发送过ejj/bjj的用户

 

  set @v_ping_noreg_con=  @v_ping_noreg –  @v_ping_noreg_ejj –  @v_ping_noreg_bjj;

 

 

 

  –统计EJJ用户      

 

  select @v_ejj_user=count(*)

 

    from tb_gl_userreplycommand

 

   where moType = ‘2’

 

     and CONVERT(char(10), sendtime,20) =CONVERT(char(10), dateadd(dd,-1,getdate()),20)

 

 

–统计BJJ用户

 

  select @v_bjj_user=count(*)

 

    from tb_gl_userreplycommand

 

   where moType = ‘1’

 

     and CONVERT(char(10), sendtime,20) =CONVERT(char(10), dateadd(dd,-1,getdate()),20)

 

 

 

—  select @v_coun =count(*)  from t_gnhd_temp where datetime = CONVERT (char(10), getdate() ,20)

 

—  if  @v_coun = 0 

    –begin 

    insert into tb_report_gnfl

 

      (ping,

 

       ping_ejj,

 

       ping_bjj,

 

       ping_con,

 

       ping_reg,

 

       ping_reg_ejj,

 

       ping_reg_bjj,

 

       ping_reg_con,

 

       man,

 

       women,

 

       age20,

 

       age29,

 

       age39,

 

       age49,

 

       age50,

 

       citysh,

 

       citybj,

 

       cityhz,

 

       citygz,

 

       citysz,

 

       cityqt,

 

       ping_noreg,

 

       ping_noreg_ejj,

 

       ping_noreg_bjj,

 

       ping_noreg_con,

 

       ejj_user,

 

       bjj_user,

 

       datetime)

 

    values(

    @v_ping,

 

        @v_ping_ejj,

 

        @v_ping_bjj,

 

        @v_ping_con,

 

        @v_ping_reg,

 

        @v_ping_reg_ejj,

 

        @v_ping_reg_bjj,

 

        @v_ping_reg_con,

 

        @v_man,

 

        @v_women,

 

        @v_age20,

 

        @v_age29,

 

        @v_age39,

 

        @v_age49,

 

        @v_age50,

 

        @v_citysh,

 

        @v_citybj,

 

        @v_cityhz,

 

        @v_citygz,

 

        @v_citysz,

 

        @v_cityqt,

 

        @v_ping_noreg,

 

        @v_ping_noreg_ejj,

 

        @v_ping_noreg_bjj,

 

        @v_ping_noreg_con,

 

        @v_ejj_user,

 

        @v_bjj_user,

     

    CONVERT(char(10), dateadd(dd,-1,getdate()),20))

 

 

GO

SET QUOTED_IDENTIFIER OFF 

GO

SET ANSI_NULLS ON 

GO

 

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/100571.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • Linux 中挖矿病毒处理过程

    Linux 中挖矿病毒处理过程分享一次Linux系统杀毒的经历,还有个人的一些总结,希望对大家有用。进程占CPU700%,进程名字是类似XY2Arv的6位随机大小写字母+数字的字符串。最终发现是一个叫systemd或trump的病毒,是一个挖矿的病毒,在挖一种叫门罗币(XMR)的数字货币。该病毒的侵入方式是通过扫描主机的Redis端口,一般默认为6379,通过Redis命令将程序注入到你的主机,Re…

    2022年5月18日
    42
  • 教你画出业务架构图「建议收藏」

    教你画出业务架构图「建议收藏」1、什么是业务架构图?业务架构图是一种表达业务层级和关系的工具,业务架构服务于业务目标,通过描绘业务上下层关系,梳理一整套完整、简单的业务视图,降低业务系统的复杂度,提高客户理解度,最终给客户最直观的业务体现。2、业务架构图的三大核心要义简单来说可以分为三个核心步骤:分层、分模块、分功能。架构图核心要义之一:分层指的是将业务按照层级区分,每个层级都属于独立的版块。下层更抽象,上层更具体。层级需要有逻辑上的关联,比如下层为上层服务,或者提供能力支撑。架构图核心要义之二:分模块分

    2022年10月12日
    3
  • initiatorname.iscsi_linux卸载iscsiadm

    initiatorname.iscsi_linux卸载iscsiadmiscsiInitiator登录target时报错iscsiadm:LoginI/Oerror,failedtoreceiveaPDU

    2022年8月22日
    7
  • 采用CreateThread()创建多线程程序[通俗易懂]

    采用CreateThread()创建多线程程序[通俗易懂]采用CreateThread()创建多线程程序在window环境下,Win32提供了一系列的API函数来完成线程的创建、挂起、恢复、终结以及通信等工作:1、主要的函数列表:序号函数名功能1CreateThread()创建一个新线程2ExitThread()正

    2022年7月11日
    22
  • Redis事务详解

    Redis事务详解若对事务概念不清楚 请先阅读 彻底理解 MySQL 四种事务隔离级别 这篇文章 链接如下 彻底理解 MySQL 四种事务隔离级别 YaoYong BigData 的博客 CSDN 博客转入正题 结合关系型数据库的事务来看看 Redis 中事务有什么不同 Redis 事务是指将多条命令加入队列 一次批量执行多条命令 每条命令会按顺序执行 事务执行过程中不会受客户端传入的命令请求影响 Redis 事务的相关命令如下 MULTI 标识一个事务的开启 即开启事务 EXEC 执行事务中的所有命令 即提

    2025年10月14日
    2
  • 手机看Typora笔记[通俗易懂]

    接触Typora之后感觉还挺好用的,不用上网,不用花钱(白嫖的玩意就是香)。可以写普通的文本,可以添加五个等级的标题,可以插入图片,,还可以插入各种各样的代码块(java,c,html,css等等),简洁而强大。但是当初我以为只能在电脑上看的时候就觉得有点难受,玛德是我S13了,我还去网上搜了半天,看看有没有教程或者手机版的软件,有的还要付费,今天我恍然大悟,尼玛人家开发个软件怎么可能没想到这些东西呢,我真是S13卧槽。看图啥都懂了:别被坑钱和C币吧…

    2022年4月3日
    202

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号