语句太长了,分几个楼层来放。part1 declare @pull varchar(100)
    declare @startid bigint
    declare @endid bigint
    declare @sql varchar(1000)
    
declare @CSDGSM varchar(100)
declare @GPRS varchar(100)
select @CSDGSM=ParamValue from waprpt.Running_Parameter where ParamName='CSDGSM' 
select @GPRS=ParamValue from waprpt.Running_Parameter where ParamName='GPRS' 
    
    exec waprpt.p_getProcessInfo 19,1,@monthday,@pull,@startid,@endid    if @startid<=@endid
    begin
        set @sql=genTmpTabSql('#province_log_pull_temp',@pull,'StartTime,BearType,KBIn,KBOut,mdn,cpStatus,serviceType,ggsnip',@startid,@endid)      
        execute (@sql)
        
     select t.timeIDD,z.ggsnip,count(distinct z.mdn) as total_user_num
     into #Wap_Service_Province_Stat_TOTAL_USER_temp1
     from #province_log_pull_temp z
     left outer join waprpt.Time_Date_Dim t
             on YEAR(z.startTime)=t.year 
             and MONTH(z.startTime)=t.month
             and DAY(z.startTime)=t."date"
     group by t.timeIDD,z.ggsnip
    
     select t.timeIDD,z.ggsnip,count(distinct z.mdn) as csd_user_num
     into #Wap_Service_Province_Stat_CSD_USER_temp1
     from #province_log_pull_temp z
     left outer join waprpt.Time_Date_Dim t
             on YEAR(z.startTime)=t.year 
             and MONTH(z.startTime)=t.month
             and DAY(z.startTime)=t."date"
     where z.beartype=@CSDGSM 
     group by t.timeIDD,z.ggsnip
    
     select t.timeIDD,z.ggsnip,count(distinct z.mdn) as gprs_user_num
     into #Wap_Service_Province_Stat_GPRS_USER_temp1
     from #province_log_pull_temp z 
     left outer join waprpt.Time_Date_Dim t
             on YEAR(z.startTime)=t.year 
             and MONTH(z.startTime)=t.month
             and DAY(z.startTime)=t."date"
     where z.beartype=@GPRS 
     group by t.timeIDD,z.ggsnip
    
     select t.timeIDD,z.ggsnip,z.beartype,count(1) as req_num,sum(isnull(z.kbin,0)+isnull(z.kbout,0)) as flow,z.cpStatus,z.servicetype
     into  #Wap_Service_Province_Stat_temp1
     from  #province_log_pull_temp z
     left outer join waprpt.Time_Date_Dim t
             on YEAR(z.startTime)=t.year 
             and MONTH(z.startTime)=t.month
             and DAY(z.startTime)=t."date"
     group by t.timeIDD,z.ggsnip,z.beartype,z.cpStatus,z.servicetype
    
     select timeIDD,ggsnip,sum(req_num) as csd_req_num,sum(flow) as csd_flow 
     into #Wap_Service_Province_Stat_CSD_temp1
     from #Wap_Service_Province_Stat_temp1
     where beartype=@CSDGSM 
     group by timeIDD,ggsnip

解决方案 »

  1.   

    part2
        
         select timeIDD,ggsnip,sum(req_num) as csd_req_succ_num
         into #Wap_Service_Province_Stat_CSD_SUCC_temp1
         from #Wap_Service_Province_Stat_temp1
         where beartype=@CSDGSM and cpStatus<400
         group by timeIDD,ggsnip 
        
         select timeIDD,ggsnip,sum(req_num) as gprs_req_num,sum(flow) as gprs_flow 
         into #Wap_Service_Province_Stat_GPRS_temp1
         from #Wap_Service_Province_Stat_temp1
         where beartype=@GPRS 
         group by timeIDD,ggsnip  
        
         select timeIDD,ggsnip,sum(req_num) as gprs_req_succ_num
         into #Wap_Service_Province_Stat_GPRS_SUCC_temp1
         from #Wap_Service_Province_Stat_temp1
         where beartype=@GPRS and cpStatus<400
         group by timeIDD,ggsnip  
        
         select timeIDD,ggsnip,sum(req_num) as total_req_num,sum(flow) as total_flow 
         into #Wap_Service_Province_Stat_TOTAL_temp1
         from #Wap_Service_Province_Stat_temp1
         group by timeIDD,ggsnip   
        
         select timeIDD,ggsnip,sum(req_num) as total_succ_req_num
         into #Wap_Service_Province_Stat_TOTAL_SUCC_temp1
         from #Wap_Service_Province_Stat_temp1
         where cpStatus<400
         group by timeIDD,ggsnip   
                
         select timeIDD,ggsnip,serviceType,sum(req_num) as serviceType_req_num
         into #Wap_Service_Province_Stat_ServiceType_temp1
         from #Wap_Service_Province_Stat_temp1
         group by timeIDD,ggsnip,serviceType  
        
         select timeIDD,ggsnip,0 as CSD_REQ_NUM,0 as CSD_SUCC_REQ_NUM,0 as CSD_USER_NUM,0 as CSD_TUNNEL_FLOW,0 as GPRS_REQ_NUM,0 as GPRS_SUCC_REQ_NUM,
         0 as GPRS_USER_NUM,0 GPRS_TUNNEL_FLOW,0 as TOTAL_REQ_NUM,0 as TOTAL_SUCC_REQ_NUM,0 as TOTAL_USER_NUM,0 as TOTAL_TUNNEL_FLOW,0 as WAP_BROWSER_REQ_NUM,
         0 as HTTP_BROWSER_REQ_NUM,0 as JAVA_LOAD_REQ_NUM,0 as MMS_POST_REQ_NUM,0 as MMS_GET_REQ_NUM,0 as PUSH_REQ_NUM,0 as ONLINE_USER_NUM
         into #Wap_Service_Province_Stat_temp 
         from #Wap_Service_Province_Stat_temp1
         group by timeIDD,ggsnip
     
      

  2.   

    part3     --更新csd请求总数、CSD Tunnel流量 
         update #Wap_Service_Province_Stat_temp set CSD_REQ_NUM=t1.csd_req_num,CSD_TUNNEL_FLOW=t1.csd_flow
         from #Wap_Service_Province_Stat_temp t,#Wap_Service_Province_Stat_CSD_temp1 t1 
         where t.timeIDD=t1.timeIDD and t.ggsnip=t1.ggsnip
        
         --更新csd成功请求总数
         update #Wap_Service_Province_Stat_temp set CSD_SUCC_REQ_NUM=t1.csd_req_succ_num
         from #Wap_Service_Province_Stat_temp t,#Wap_Service_Province_Stat_CSD_SUCC_temp1 t1 
         where t.timeIDD=t1.timeIDD and t.ggsnip=t1.ggsnip  
        
         --更新gprs请求总数、GPRS Tunnel流量   
         update #Wap_Service_Province_Stat_temp set GPRS_REQ_NUM=t1.gprs_req_num,GPRS_TUNNEL_FLOW=t1.gprs_flow
         from #Wap_Service_Province_Stat_temp t,#Wap_Service_Province_Stat_GPRS_temp1 t1 
         where t.timeIDD=t1.timeIDD and t.ggsnip=t1.ggsnip 
        
         --更新gprs成功请求总数
         update #Wap_Service_Province_Stat_temp set GPRS_SUCC_REQ_NUM=t1.gprs_req_succ_num
         from #Wap_Service_Province_Stat_temp t,#Wap_Service_Province_Stat_GPRS_SUCC_temp1 t1 
         where t.timeIDD=t1.timeIDD and t.ggsnip=t1.ggsnip 
        
         --更新请求总数、Tunnel流量   
         update #Wap_Service_Province_Stat_temp set TOTAL_REQ_NUM=t1.total_req_num,TOTAL_TUNNEL_FLOW=t1.total_flow
         from #Wap_Service_Province_Stat_temp t,#Wap_Service_Province_Stat_TOTAL_temp1 t1 
         where t.timeIDD=t1.timeIDD and t.ggsnip=t1.ggsnip 
        
         --更新成功请求总数
         update #Wap_Service_Province_Stat_temp set TOTAL_SUCC_REQ_NUM=t1.total_succ_req_num
         from #Wap_Service_Province_Stat_temp t,#Wap_Service_Province_Stat_TOTAL_SUCC_temp1 t1 
         where t.timeIDD=t1.timeIDD and t.ggsnip=t1.ggsnip 
        
         --更新WAP浏览请求数、HTTP浏览请求数、JAVA下载请求数、彩信POST请求数、彩信GET请求数
         update #Wap_Service_Province_Stat_temp set WAP_BROWSER_REQ_NUM=t1.serviceType_req_num
         from #Wap_Service_Province_Stat_temp t,#Wap_Service_Province_Stat_ServiceType_temp1 t1 
         where t.timeIDD=t1.timeIDD and t.ggsnip=t1.ggsnip and t1.serviceType='001'
         update #Wap_Service_Province_Stat_temp set HTTP_BROWSER_REQ_NUM=t1.serviceType_req_num
         from #Wap_Service_Province_Stat_temp t,#Wap_Service_Province_Stat_ServiceType_temp1 t1 
         where t.timeIDD=t1.timeIDD and t.ggsnip=t1.ggsnip and t1.serviceType='002'
         update #Wap_Service_Province_Stat_temp set JAVA_LOAD_REQ_NUM=t1.serviceType_req_num
         from #Wap_Service_Province_Stat_temp t,#Wap_Service_Province_Stat_ServiceType_temp1 t1 
         where t.timeIDD=t1.timeIDD and t.ggsnip=t1.ggsnip and t1.serviceType='003'
         update #Wap_Service_Province_Stat_temp set MMS_POST_REQ_NUM=t1.serviceType_req_num
         from #Wap_Service_Province_Stat_temp t,#Wap_Service_Province_Stat_ServiceType_temp1 t1 
         where t.timeIDD=t1.timeIDD and t.ggsnip=t1.ggsnip and t1.serviceType='004'
         update #Wap_Service_Province_Stat_temp set MMS_GET_REQ_NUM=t1.serviceType_req_num
         from #Wap_Service_Province_Stat_temp t,#Wap_Service_Province_Stat_ServiceType_temp1 t1 
         where t.timeIDD=t1.timeIDD and t.ggsnip=t1.ggsnip and t1.serviceType='005'
        
         update #Wap_Service_Province_Stat_temp set TOTAL_USER_NUM=t1.total_user_num
         from #Wap_Service_Province_Stat_temp t,#Wap_Service_Province_Stat_TOTAL_USER_temp1 t1 
         where t.timeIDD=t1.timeIDD and t.ggsnip=t1.ggsnip    
        
         update #Wap_Service_Province_Stat_temp set CSD_USER_NUM=t1.csd_user_num
         from #Wap_Service_Province_Stat_temp t,#Wap_Service_Province_Stat_CSD_USER_temp1 t1 
         where t.timeIDD=t1.timeIDD and t.ggsnip=t1.ggsnip 
        
         update #Wap_Service_Province_Stat_temp set GPRS_USER_NUM=t1.gprs_user_num
         from #Wap_Service_Province_Stat_temp t,#Wap_Service_Province_Stat_GPRS_USER_temp1 t1 
         where t.timeIDD=t1.timeIDD and t.ggsnip=t1.ggsnip 
     
            select * from #Wap_Service_Province_Stat_temp
      

  3.   

    一共三个部分代码发送完毕。这段代码使用了大量的临时表,当大数据量时严重影响了执行效率,求简化(@_@,自己已经绕晕了)简单的说下代码功能--part1里的这句话
    exec waprpt.p_getProcessInfo 19,1,@monthday,@pull,@startid,@endid
    --作用是把一部分记录取出指定表@pull的开始ID和结束ID,这里的@monthday是个入餐不用理会--part1里的这句话
            set @sql=genTmpTabSql('#province_log_pull_temp',@pull,'StartTime,BearType,KBIn,KBOut,mdn,cpStatus,serviceType,ggsnip',@startid,@endid)      
            execute (@sql)
    --作用是把表@pull里面大于开始ID和小于结束ID的记录取到临时表#province_log_pull_temp里面,具体不用关注。
      

  4.   

    然后代码就按块来看了part1里的前三个select 块是用三个规则统计三个用户数part1里的第四个select 块是建立一张临时表#Wap_Service_Province_Stat_temp1,供后面的代码使用然后part1里的第5个select块(part1的最后一个)和part2的前六个代码块是用上面的临时表用不同的规则统计出一些数据part2的第七个(part2的最后一个)是建立最终的临时表#Wap_Service_Province_Stat_temp 来存放所有的统计信息part3的所有部分都是把part1 part2的统计部分放到那个最终临时表里的
      

  5.   

    代码在顶楼,1楼,3楼说明在7楼流程在9楼补充一个waprpt.Time_Date_Dim 是一张时间纬度表,用一个timeIDD来表示年月日的有人接手处理么?
      

  6.   

    稍微看了一下,觉得lz里面的有些东西是可以合并的。例如:select timeIDD,ggsnip,sum(req_num) as csd_req_succ_num
            into #Wap_Service_Province_Stat_CSD_SUCC_temp1
            from #Wap_Service_Province_Stat_temp1
            where beartype=@CSDGSM and cpStatus<400
            group by timeIDD,ggsnip 
    与      
          select timeIDD,ggsnip,sum(req_num) as gprs_req_succ_num
            into #Wap_Service_Province_Stat_GPRS_SUCC_temp1
            from #Wap_Service_Province_Stat_temp1
            where beartype=@GPRS and cpStatus<400
            group by timeIDD,ggsnip  
    完全可以放到一张表啊,这样的话可以减少很多的临时表
    合并成:
          select timeIDD,ggsnip,sum(req_num) as csd_req_succ_num,sum(req_num) as gprs_req_succ_num
            into #Wap_Service_Province_Stat_GPRS_SUCC_temp1
            from #Wap_Service_Province_Stat_temp1
            where beartype=@GPRS and cpStatus<400
            group by timeIDD,ggsnip  
      

  7.   

    回复11楼:  那种合并方法是错误的,where的条件不一样
      

  8.   

    where beartype=@CSDGSM where beartype=@GPRS
    --
    可以合并
    where (beartype=@CSDGSM or beartype=@GPRS)
      

  9.   

    回复13楼,不行的,上面select sum()里面的字段是相同的,改成条件1or条件2后结果就不同了回复14楼,这个应该怎么使用表变量?
      

  10.   


    简化?
    用CSDN上的分 雇人给你干活呢啊?