条件中的SQL Server条件
我想说: “如果前两个字母不是10,且以10开头的字母仅排除2018年以后的字母”条件中的SQL Server条件,sql,sql-server,Sql,Sql Server,我想说: “如果前两个字母不是10,且以10开头的字母仅排除2018年以后的字母” where (left(c.DealCode, 2) <> '10' and estyear > 2018) 不起作用。。我错过了什么 你说: where left(c.DealCode, 2) <> '10' or (left(c.DealCode, 2) = '10' and estyear > 2018) '其中前两个字母不是10,对于那些确实以10开头的字母
where (left(c.DealCode, 2) <> '10'
and estyear > 2018)
不起作用。。我错过了什么 你说:
where left(c.DealCode, 2) <> '10' or (left(c.DealCode, 2) = '10' and estyear > 2018)
'其中前两个字母不是10,对于那些确实以10开头的字母
只有10个不包括2018年以后的'
但是你应该说:
'其中前两个字母不是10,或者是那些以10开头的字母
只有10个不包括2018年以后的'
所以你必须在你的陈述中用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
但不确定是否
不包括2018年以后的
必须是estyear>2018或estyear<2018编辑问题,添加一些样本数据,期望的结果会有所帮助。
where c.DealCode not like '10%' or estyear > 2018