SELECT place,username,dt,
IF(dt=last_day('2009-05-01') and (place!='leroy' or place!='starworld'),amount,0)
FROM CasinoRolling where username='888888888' 
为什么查出来  dt=last_day('2009-05-01')  and place='starworld' 的 amount不显示为0!

解决方案 »

  1.   

    (place!='leroy'or place!='starworld')这是个逻辑错误,恒为 true !
      

  2.   


    (place='leroy'or place='starworld')
    place 等于  leroy 或者等于 starworld这个在逻辑上一点问题都没有!(place!='leroy'or place!='starworld')place 不等于  leroy 或者 不等于 starworld
    就算place 是任何值,总一个 (place 不等于  leroy ) 或者 (place 不等于  starworld ) 为真!楼主的逻辑没搞清楚,用汉字说明一下你想做的事!估计你是想要
    IF(dt=last_day('2009-05-01') and not (place='leroy'or place='starworld'),amount,0)
      

  3.   


    SELECT place,username,dt,
    IF(dt=last_day('2009-05-01') and (place!='leroy' or place!='starworld'),amount,0)
    FROM CasinoRolling where username='888888888'我想要的结果是
    -------------------------------------------------------------------------------------------------------------------
     place   |  username  |      dt     |   IF(dt=last_day('2009-05-01') and (place!='leroy' or place!='starworld'),amount,0)
    -------------------------------------------------------------------------------------------------------------------
      aaa    | 888888888 | 2009-05-31  |  5000
      bbb    | 888888888 | 2009-05-31  |  2000
      leroy  | 888888888 | 2009-05-31  |  0    [这个时候条件不满足:place!='leroy' 就给amount显示0]
      ccccc  | 888888888 | 2009-05-31  |  6000
    starworld| 888888888 | 2009-05-31  |  0    [这个时候条件也不满足:place!='leroy' 就给amount显示0]也就是说但时间是2009-05-31的时候,但 place='leroy' or place='starworld' 的话 amount就显示0
    这样写可以实现:
    IF(substring(from_days(floor(shift/10)+719528),1,10)=last_day('2009-05-01') and place='starworld' or place='leroy',0,amount)
    但我现在需要同时判非的实现,这是我简化来的一个小查询.
    不知道我说清楚了么?各位高人有没理解我意思的继续问我!
      

  4.   

    自己明白了,不是用or,是用and!脑袋短路..............,谢谢各位!