select *
from authors
where first_name like '%_e%' and gender='M' or not author_id>=16问下,这句sql的执行顺序是怎么样的,主要是where后面的执行顺序,and跟or混在一起的时候,如何执行?

解决方案 »

  1.   

    and 优先级高于 or,该语句等价于下例:select * from authors 
    where (first_name like '%_e%' and gender='M') or not author_id>=16
      

  2.   

    不是他们混了,是你混了,建议改为select *
    from authors
    where (first_name like '%_e%' and gender='M') or author_id<16select *
    from authors
    where first_name like '%_e%' and (gender='M' or author_id<16)
      

  3.   


    and的优先级比or要高,所以先执行and再执行or
    相当于SQL codeselect *
    from authors
    where (first_name like '%_e%' and gender='M') or not author_id>=16
      

  4.   

    hehe,楼上都说完了,我就不补充了