select c.bureau_no,d.site_no,
count (distinct case when b.offer_type='e6' then a.id end  ) as t,
count (distinct case when b.offer_type='e6' and to_char(a.date, 'ww') = to_char(sysdate, 'ww') then a.id end  ) as t1,
count (distinct case when b.offer_type='e6' and to_char(a.date, 'ww') = to_char(sysdate -1, 'ww') then a.id end  ) as t2,
count (distinct case when b.offer_type='e6' and to_char(a.date, 'ww') = to_char(sysdate -2, 'ww')then a.id ) as t3
from TABLENAME a,请大家帮我解决下 为何 我的T1,T2,T3 取出来的数值是一样的? 特郁闷 谢谢大家了

解决方案 »

  1.   

    count (distinct case when b.offer_type='e6' and to_char(a.date, 'ww') = to_char(sysdate, 'ww') then 1 else null end  ) as t1,
      

  2.   

    还是不行啊 数字还是一样的。。 a.id 这个是必须是唯一的 大家帮帮我
      

  3.   

    1楼的答案是对了。count在统计时,如果是null就不加数量是不是你的数据问题?a.date都是本周内的?
      

  4.   

    a.date 不是本周内的, 现在 就是特郁闷 取出来的T1,T2,T3的时间就是一样的。不知道怎么回事。
      

  5.   

    具体情况是  a.id 可能有重复的  我要取唯一的 ,如果直接distinct  如果其他字段不一样的话 就会取多了现在问题是 t1.t2,t3 时间段取出数据的是一样的 大家帮帮我 谢谢了
      

  6.   

    SQL> select to_char(sysdate,'ww') from dual;TO
    --
    15SQL> ed
    ÒÑдÈëÎļþ afiedt.buf  1* select to_char(sysdate-1,'ww') from dual
    SQL> /TO
    --
    15SQL> ed
     为什么一样说明在同一周啊 
      

  7.   

    SQL> select to_char(sysdate,'ww') from dual;TO
    --
    15SQL> ed
    已写入文件 afiedt.buf  1* select to_char(sysdate-1,'ww') from dual
    SQL> /TO
    --
    15为什么一样说明在同一周啊
      

  8.   

    我MS找到原因了 SYSDATE  这个按天算 谢谢大家
      

  9.   

    SQL> select to_char(sysdate,'ww')-1 from dual;TO_CHAR(SYSDATE,'WW')-1
    -----------------------
                         14SQL> select to_char(sysdate,'ww')-2 from dual;TO_CHAR(SYSDATE,'WW')-2
    -----------------------
                         13SQL> 
    这样吧,楼主懂吗
      

  10.   

    sysdate -1 是系统时间前一天,你要减7