在where子句中使用多个搜索需要帮助:
尝试编写一个查询,它将以“已完成关闭”,“已关闭未完成”,“已关闭已跳过”返回票证,并排除列中包含项目的行,但如果包含投影仪,ms项目,项目2016,投影仪则不应排除
这是我到目前为止的查询:
请让我知道我在这里做错了什么
Select
CONCAT(YEAR(a.[closed_at]),'-',DATENAME(MONTH,a.[closed_at])) as [Year_Month],
a.[Number],
a.[closed_at],
b.[Region],
b.[Tower_Name],
a.[Short_description],
a.[description]
from [dbo].[sc_task_master_data] a
right join [dbo].[Master_Assignee_list] b
on a.[assignment_group]=b.Assignee_Group_Name
where a.[state] IN ('Closed Complete','Closed Incomplete','Closed Skipped')
and a.[short_description] not like '%project%'
and a.[short_description] like '%project 2%'
and a.[short_description] like '%MS Project%'
and a.[short_description] like '%PROJECT 20%'
and a.[short_description] like '%project installation%'
and a.[short_description] like '%Microsoft Project%'
and a.[short_description] like '%Projector%'
and a.[number] in ('SCTASK0050503', 'SCTASK0050510','SCTASK0051162')
谢谢!
你的WHERE
条款只包括AND
s,这意味着之前和之后的条件必须匹配。
您可以修改您的语句以包括括号,该括号将子句有效地组合在一起以具有单个逻辑结果,例如:
where a.[state] IN ('Closed Complete','Closed Incomplete','Closed Skipped')
and (a.[short_description] not like '%project%'
or a.[short_description] like '%project 2%'
or a.[short_description] like '%MS Project%'
or a.[short_description] like '%PROJECT 20%'
or a.[short_description] like '%project installation%'
or a.[short_description] like '%Microsoft Project%'
or a.[short_description] like '%Projector%')
and a.[number] in ('SCTASK0050503', 'SCTASK0050510','SCTASK0051162')
注意第二行和倒数第二行中的括号,它们将这些子句组合在一起,这样如果它们中的任何一个为真,它将是真的。