我目前需要按周统计数据,我自己能够按自然周统计,但是现在需要一周的统计时间与自然周偏移3天;
例如自然周是周一到周日,我现在统计的一周是上周五到本周四,请问如果写SQL语句??
select sum(a),sum(b),sum(c),sum(d),sum(e),sum(g),f from 
(
select count(*) a,0 as b,0 as c,0 as d,0 as e,0 as g,to_char(complaints_date,'ww') f from dh_complaints t
 where complaints_Type='类型' and complaints_date between :begin_Time and :end_Time                                                                                       
   group by to_char(complaints_date,'ww')     
) x
 group by x.f

解决方案 »

  1.   

    你用偏移量就是了to_char(complaints_date+4,'ww');
    至于加几自己测试;
      

  2.   


    select sum(a), sum(b), sum(c), sum(d), sum(e), sum(g), f
      from (select count(*) a,
                   0 as b,
                   0 as c,
                   0 as d,
                   0 as e,
                   0 as g,
                   to_char(complaints_date - 3, 'ww') f
              from dh_complaints t
             where complaints_Type = '类型'
               and complaints_date - 3 between :begin_Time and :end_Time
             group by to_char(complaints_date - 3, 'ww')) x
     group by x.f;