代码之家  ›  专栏  ›  技术社区  ›  punkouter

条件内的SQL Server条件

  •  -3
  • punkouter  · 技术社区  · 6 年前

    我想说:

    “前两个字母不是10,而以10开头的字母则不包括2018年以后的字母”

    where (left(c.DealCode, 2) <> '10'
        and estyear > 2018)
    

    不起作用。。我错过了什么?

    2 回复  |  直到 6 年前
        1
  •  3
  •   DanB    6 年前
    where left(c.DealCode, 2) <> '10' or (left(c.DealCode, 2) = '10' and estyear > 2018)
    

    where c.DealCode not like '10%' or (c.DealCode like '10%' and estyear > 2018)
    
        2
  •  2
  •   forpas    6 年前

    你说:

    前两个字母不是10 只有10个不包括2018年以后的


    前两个字母不是10 对于那些真正开始

    所以你必须使用 OR 而不是 AND
    还有一种说法是:

    (a doesn't start with 10) or ((a starts with 10) and (estyear > 2018))
    

    (a doesn't start with 10) or (estyear > 2018)
    

    所以你的情况应该是:

    where c.DealCode not like '10%' or estyear > 2018
    

    但不确定如果


    必须是 estyear > 2018 estyear < 2018