解决方案 »

  1.   

    那其实结果是这样的:12号成交的不管是什么时候建单的都要统计到建单量里面,但是12号建单的但不是12号成交的就不统计到成交量里面
    是这样吧?
    是这样的 哪天建单建单量就算在你那天。哪天成交的成交量就算在那天。
    比如 统计12号的数据。 11号建的单,但在12号成交。那么这单的建单量属于11号。但他的属于12好的成交量。
    这就是那种12号这项服务有成交量而没有建单量情况,因为他的建单时间在11号。(表达不是很清晰,不知道您能否理解)select a.servicetype,
           a.ordersource,
           sum(case
                 when (a.create_time between to_date('2015-01-12', 'yyyy-mm-dd') and
                      to_date('2015-01-12 23:59:59', 'yyyy-mm-dd hh24:mi:ss')) or
                      (a.deal_time between to_date('2015-01-12', 'yyyy-mm-dd') and
                      to_date('2015-01-12 23:59:59', 'yyyy-mm-dd hh24:mi:ss') and
                      a.create_time <
                      to_date('2015-01-12', 'yyyy-mm-dd')) then
                  1
                 else
                  0
               end) create_num,
               sum(case when a.deal_time between to_date('2015-01-12', 'yyyy-mm-dd') and
                      to_date('2015-01-12 23:59:59', 'yyyy-mm-dd hh24:mi:ss') then 1 else 0 end) deal_num
      from t_order a
      group by  a.servicetype,
           a.ordersource;
    你看看是这个意思吧?如果是的的话再做一次行列转换就可以了
      

  2.   

    那其实结果是这样的:12号成交的不管是什么时候建单的都要统计到建单量里面,但是12号建单的但不是12号成交的就不统计到成交量里面
    是这样吧?
    是这样的 哪天建单建单量就算在你那天。哪天成交的成交量就算在那天。
    比如 统计12号的数据。 11号建的单,但在12号成交。那么这单的建单量属于11号。但他的属于12好的成交量。
    这就是那种12号这项服务有成交量而没有建单量情况,因为他的建单时间在11号。(表达不是很清晰,不知道您能否理解)select a.servicetype,
           a.ordersource,
           sum(case
                 when (a.create_time between to_date('2015-01-12', 'yyyy-mm-dd') and
                      to_date('2015-01-12 23:59:59', 'yyyy-mm-dd hh24:mi:ss')) or
                      (a.deal_time between to_date('2015-01-12', 'yyyy-mm-dd') and
                      to_date('2015-01-12 23:59:59', 'yyyy-mm-dd hh24:mi:ss') and
                      a.create_time <
                      to_date('2015-01-12', 'yyyy-mm-dd')) then
                  1
                 else
                  0
               end) create_num,
               sum(case when a.deal_time between to_date('2015-01-12', 'yyyy-mm-dd') and
                      to_date('2015-01-12 23:59:59', 'yyyy-mm-dd hh24:mi:ss') then 1 else 0 end) deal_num
      from t_order a
      group by  a.servicetype,
           a.ordersource;
    你看看是这个意思吧?如果是的的话再做一次行列转换就可以了
    行转列不太知道思路,
    所以我这样做 ,计算百分比好长我这样, 
    select 
          m.servicetype 服务类别,
           --来源1
          sum( case when m.create_time between trunc(sysdate-3,'dd') and trunc(sysdate,'dd') and m.order_source = '1' then 1 else 0 end) 建单量 ,    
          sum( case when m.deal_time between trunc(sysdate-3,'dd') and trunc(sysdate,'dd') 
              and m.order_source = '1' and m.deal_state='1' then 1 else 0 end)  成交量, 
              
           round(decode( 
                 sum( case when m.create_time between trunc(sysdate-3,'dd') and trunc(sysdate,'dd') and m.order_source = '1' then 1 else 0 end),'0','0', --分母是否为 0           
                 sum( case when m.deal_time between trunc(sysdate-3,'dd') and trunc(sysdate,'dd') --计算成交率
                   and m.order_source = '1' and m.deal_state='1' then 1 else 0 end)/
                   sum( case when m.create_time between trunc(sysdate-3,'dd') and trunc(sysdate,'dd') and m.order_source = '1' then 1 else 0 end)
                          
              )*100,2) 成交率,
              
          sum( case when m.deal_time between trunc(sysdate-3,'dd') and trunc(sysdate,'dd') 
              and m.order_source = '1' and m.deal_state='1' then m.charge else '0' end)  成交金额 ,
         --来源2     
               sum( case when m.create_time between trunc(sysdate-3,'dd') and trunc(sysdate,'dd') and m.order_source = '1' then 1 else 0 end) 建单量 ,    
          sum( case when m.deal_time between trunc(sysdate-3,'dd') and trunc(sysdate,'dd') 
              and m.order_source = '1' and m.deal_state='1' then 1 else 0 end)  成交量, 
              
           round(decode( 
                 sum( case when m.create_time between trunc(sysdate-3,'dd') and trunc(sysdate,'dd') and m.order_source = '1' then 1 else 0 end),'0','0', --分母是否为 0           
                 sum( case when m.deal_time between trunc(sysdate-3,'dd') and trunc(sysdate,'dd') --计算成交率
                   and m.order_source = '1' and m.deal_state='1' then 1 else 0 end)/
                   sum( case when m.create_time between trunc(sysdate-3,'dd') and trunc(sysdate,'dd') and m.order_source = '1' then 1 else 0 end)
                          
              )*100,2) 成交率,
              
          sum( case when m.deal_time between trunc(sysdate-3,'dd') and trunc(sysdate,'dd') 
              and m.order_source = '1' and m.deal_state='1' then m.charge else '0' end)  成交金额      
          
      from t_Order_List m   
      where  m.create_time between trunc(sysdate-3,'dd') and trunc(sysdate,'dd')
      or m.deal_time between trunc(sysdate-3,'dd') and trunc(sysdate,'dd')
      
      group by m.service_type_second_id
    那其实结果是这样的:12号成交的不管是什么时候建单的都要统计到建单量里面,但是12号建单的但不是12号成交的就不统计到成交量里面
    是这样吧?
    是这样的 哪天建单建单量就算在你那天。哪天成交的成交量就算在那天。
    比如 统计12号的数据。 11号建的单,但在12号成交。那么这单的建单量属于11号。但他的属于12好的成交量。
    这就是那种12号这项服务有成交量而没有建单量情况,因为他的建单时间在11号。(表达不是很清晰,不知道您能否理解)select a.servicetype,
           a.ordersource,
           sum(case
                 when (a.create_time between to_date('2015-01-12', 'yyyy-mm-dd') and
                      to_date('2015-01-12 23:59:59', 'yyyy-mm-dd hh24:mi:ss')) or
                      (a.deal_time between to_date('2015-01-12', 'yyyy-mm-dd') and
                      to_date('2015-01-12 23:59:59', 'yyyy-mm-dd hh24:mi:ss') and
                      a.create_time <
                      to_date('2015-01-12', 'yyyy-mm-dd')) then
                  1
                 else
                  0
               end) create_num,
               sum(case when a.deal_time between to_date('2015-01-12', 'yyyy-mm-dd') and
                      to_date('2015-01-12 23:59:59', 'yyyy-mm-dd hh24:mi:ss') then 1 else 0 end) deal_num
      from t_order a
      group by  a.servicetype,
           a.ordersource;
    你看看是这个意思吧?如果是的的话再做一次行列转换就可以了那其实结果是这样的:12号成交的不管是什么时候建单的都要统计到建单量里面,但是12号建单的但不是12号成交的就不统计到成交量里面
    是这样吧?
    是这样的 哪天建单建单量就算在你那天。哪天成交的成交量就算在那天。
    比如 统计12号的数据。 11号建的单,但在12号成交。那么这单的建单量属于11号。但他的属于12好的成交量。
    这就是那种12号这项服务有成交量而没有建单量情况,因为他的建单时间在11号。(表达不是很清晰,不知道您能否理解)select a.servicetype,
           a.ordersource,
           sum(case
                 when (a.create_time between to_date('2015-01-12', 'yyyy-mm-dd') and
                      to_date('2015-01-12 23:59:59', 'yyyy-mm-dd hh24:mi:ss')) or
                      (a.deal_time between to_date('2015-01-12', 'yyyy-mm-dd') and
                      to_date('2015-01-12 23:59:59', 'yyyy-mm-dd hh24:mi:ss') and
                      a.create_time <
                      to_date('2015-01-12', 'yyyy-mm-dd')) then
                  1
                 else
                  0
               end) create_num,
               sum(case when a.deal_time between to_date('2015-01-12', 'yyyy-mm-dd') and
                      to_date('2015-01-12 23:59:59', 'yyyy-mm-dd hh24:mi:ss') then 1 else 0 end) deal_num
      from t_order a
      group by  a.servicetype,
           a.ordersource;
    你看看是这个意思吧?如果是的的话再做一次行列转换就可以了那其实结果是这样的:12号成交的不管是什么时候建单的都要统计到建单量里面,但是12号建单的但不是12号成交的就不统计到成交量里面
    是这样吧?
    是这样的 哪天建单建单量就算在你那天。哪天成交的成交量就算在那天。
    比如 统计12号的数据。 11号建的单,但在12号成交。那么这单的建单量属于11号。但他的属于12好的成交量。
    这就是那种12号这项服务有成交量而没有建单量情况,因为他的建单时间在11号。(表达不是很清晰,不知道您能否理解)select a.servicetype,
           a.ordersource,
           sum(case
                 when (a.create_time between to_date('2015-01-12', 'yyyy-mm-dd') and
                      to_date('2015-01-12 23:59:59', 'yyyy-mm-dd hh24:mi:ss')) or
                      (a.deal_time between to_date('2015-01-12', 'yyyy-mm-dd') and
                      to_date('2015-01-12 23:59:59', 'yyyy-mm-dd hh24:mi:ss') and
                      a.create_time <
                      to_date('2015-01-12', 'yyyy-mm-dd')) then
                  1
                 else
                  0
               end) create_num,
               sum(case when a.deal_time between to_date('2015-01-12', 'yyyy-mm-dd') and
                      to_date('2015-01-12 23:59:59', 'yyyy-mm-dd hh24:mi:ss') then 1 else 0 end) deal_num
      from t_order a
      group by  a.servicetype,
           a.ordersource;
    你看看是这个意思吧?如果是的的话再做一次行列转换就可以了行转列不太知道思路,
    所以我这样做 ,计算百分比好长我这样,再计算百分比时有什么好的做法吗?
    select 
          m.servicetype 服务类别,
           --来源1
          sum( case when m.create_time between trunc(sysdate-3,'dd') and trunc(sysdate,'dd') and m.order_source = '1' then 1 else 0 end) 建单量 ,    
          sum( case when m.deal_time between trunc(sysdate-3,'dd') and trunc(sysdate,'dd') 
              and m.order_source = '1' and m.deal_state='1' then 1 else 0 end)  成交量, 
              
           round(decode( 
                 sum( case when m.create_time between trunc(sysdate-3,'dd') and trunc(sysdate,'dd') and m.order_source = '1' then 1 else 0 end),'0','0', --分母是否为 0           
                 sum( case when m.deal_time between trunc(sysdate-3,'dd') and trunc(sysdate,'dd') --计算成交率
                   and m.order_source = '1' and m.deal_state='1' then 1 else 0 end)/
                   sum( case when m.create_time between trunc(sysdate-3,'dd') and trunc(sysdate,'dd') and m.order_source = '1' then 1 else 0 end)
                          
              )*100,2) 成交率,
              
          sum( case when m.deal_time between trunc(sysdate-3,'dd') and trunc(sysdate,'dd') 
              and m.order_source = '1' and m.deal_state='1' then m.charge else '0' end)  成交金额 ,
        
      

  3.   

    那其实结果是这样的:12号成交的不管是什么时候建单的都要统计到建单量里面,但是12号建单的但不是12号成交的就不统计到成交量里面
    是这样吧?
    是这样的 哪天建单建单量就算在你那天。哪天成交的成交量就算在那天。
    比如 统计12号的数据。 11号建的单,但在12号成交。那么这单的建单量属于11号。但他的属于12好的成交量。
    这就是那种12号这项服务有成交量而没有建单量情况,因为他的建单时间在11号。(表达不是很清晰,不知道您能否理解)select a.servicetype,
           a.ordersource,
           sum(case
                 when (a.create_time between to_date('2015-01-12', 'yyyy-mm-dd') and
                      to_date('2015-01-12 23:59:59', 'yyyy-mm-dd hh24:mi:ss')) or
                      (a.deal_time between to_date('2015-01-12', 'yyyy-mm-dd') and
                      to_date('2015-01-12 23:59:59', 'yyyy-mm-dd hh24:mi:ss') and
                      a.create_time <
                      to_date('2015-01-12', 'yyyy-mm-dd')) then
                  1
                 else
                  0
               end) create_num,
               sum(case when a.deal_time between to_date('2015-01-12', 'yyyy-mm-dd') and
                      to_date('2015-01-12 23:59:59', 'yyyy-mm-dd hh24:mi:ss') then 1 else 0 end) deal_num
      from t_order a
      group by  a.servicetype,
           a.ordersource;
    你看看是这个意思吧?如果是的的话再做一次行列转换就可以了 --来源2     
               sum( case when m.create_time between trunc(sysdate-3,'dd') and trunc(sysdate,'dd') and m.order_source = '1' then 1 else 0 end) 建单量 ,    
          sum( case when m.deal_time between trunc(sysdate-3,'dd') and trunc(sysdate,'dd') 
              and m.order_source = '1' and m.deal_state='1' then 1 else 0 end)  成交量, 
              
           round(decode( 
                 sum( case when m.create_time between trunc(sysdate-3,'dd') and trunc(sysdate,'dd') and m.order_source = '1' then 1 else 0 end),'0','0', --分母是否为 0           
                 sum( case when m.deal_time between trunc(sysdate-3,'dd') and trunc(sysdate,'dd') --计算成交率
                   and m.order_source = '1' and m.deal_state='1' then 1 else 0 end)/
                   sum( case when m.create_time between trunc(sysdate-3,'dd') and trunc(sysdate,'dd') and m.order_source = '1' then 1 else 0 end)
                          
              )*100,2) 成交率,
              
          sum( case when m.deal_time between trunc(sysdate-3,'dd') and trunc(sysdate,'dd') 
              and m.order_source = '1' and m.deal_state='1' then m.charge else '0' end)  成交金额      
          
      from t_Order_List m   
      where  m.create_time between trunc(sysdate-3,'dd') and trunc(sysdate,'dd')
      or m.deal_time between trunc(sysdate-3,'dd') and trunc(sysdate,'dd')
      
      group by m.service_type_second_id