如题
select  to_char(ubac.usetime,'yyyy-mm-dd'
from wap_t_comm_manufacturer      cm  
    join wap_t_re_manufacturer_channel rmc  on rmc.E_id=cm.ID  join wap_t_comm_channel            cc   on cc.id=rmc.catagory_id  
    join wap_t_re_business_channel     rbc  on rbc.soid=cc.id  join wap_t_comm_business           cb   on cb.id=rbc.opid   
    join wap_t_comm_sp                 cs   on cs.spno=cb.sp_id  join wap_t_user_business_access    ubac on ubac.opno=cb.opno  
where ubac.usetime between to_date('2009-05-01 00','yyyy-mm-dd hh24:mi:ss') and to_date('2009-05-31 00','yyyy-mm-dd hh24:mi:ss')  
group by  to_char(ubac.usetime,'yyyy-mm-dd')为什么得到的结果有四月的数据?

解决方案 »

  1.   


    发现一个很奇怪的问题如果查询语句如下,即时间限定在where的最前面,就会出现四月分的数据
    select  to_char(ubac.usetime,'yyyy-mm-dd' 
    from wap_t_comm_manufacturer      cm  
        join wap_t_re_manufacturer_channel rmc  on rmc.E_id=cm.ID  join wap_t_comm_channel            cc  on cc.id=rmc.catagory_id  
        join wap_t_re_business_channel    rbc  on rbc.soid=cc.id  join wap_t_comm_business          cb  on cb.id=rbc.opid  
        join wap_t_comm_sp                cs  on cs.spno=cb.sp_id  join wap_t_user_business_access    ubac on ubac.opno=cb.opno  
    where ubac.usetime between to_date('2009-05-01 00','yyyy-mm-dd hh24:mi:ss') and to_date('2009-05-31 00','yyyy-mm-dd hh24:mi:ss')
        and cb.id='123' or cb.opno='123'   
    group by  to_char(ubac.usetime,'yyyy-mm-dd') 但是如果时间限定在where的最后面,就不会出现四月份的数据,难道where中条件的顺序也会影响结果吗?
    select  to_char(ubac.usetime,'yyyy-mm-dd' 
    from wap_t_comm_manufacturer      cm  
        join wap_t_re_manufacturer_channel rmc  on rmc.E_id=cm.ID  join wap_t_comm_channel            cc  on cc.id=rmc.catagory_id  
        join wap_t_re_business_channel    rbc  on rbc.soid=cc.id  join wap_t_comm_business          cb  on cb.id=rbc.opid  
        join wap_t_comm_sp                cs  on cs.spno=cb.sp_id  join wap_t_user_business_access    ubac on ubac.opno=cb.opno  
    where   cb.id='123' or cb.opno='123'   and  
        ubac.usetime between to_date('2009-05-01 00','yyyy-mm-dd hh24:mi:ss') and to_date('2009-05-31 00','yyyy-mm-dd hh24:mi:ss')
    group by  to_char(ubac.usetime,'yyyy-mm-dd') 
      

  2.   

    会不会是因为位数不对啊? to_date('2009-05-01 00','yyyy-mm-dd hh24:mi:ss') 前面的字符串没有分钟和秒?导致To_Date数据出错了呢?
      

  3.   

    呵呵 应该是and与or的顺序有关! 前面那个应该使用括号的 
      

  4.   

    应该不是吧,我查了下,好像有说where条件的顺序对查询结果是有影响的,是不是这样啊,期待高手!怎样的情况下where条件的顺序会对结果产生影响呢?
      

  5.   

    第一个条件 这样写:
    where ubac.usetime between to_date('2009-05-01 00','yyyy-mm-dd hh24:mi:ss') and to_date('2009-05-31 00','yyyy-mm-dd hh24:mi:ss') 
    and (cb.id='123' or cb.opno='123')  
    应该可以的!
    明显有括号和无括号的意思不一样的!
      

  6.   

    and和or的判定顺序问题,把or的判别条件单独用括号括起来就好了,lz试试
      

  7.   

    果然如此,是and和or的判定顺序的问题,汗,如果真是自己查不知要查到什么时候,谢谢各位了