0

我正在尝试从我们的客户服务查询中选择一些消息,其中 Mmessage 所有者是 ABC,数据是 LIKE ABCDEF 和消息......并且消息是从客户到 CSservice 或从 CSservice 到客户。

我怎样才能做到这一点?

SELECT Date, From, To, Data 
FROM Ccustomers WITH (NoLock)
WHERE MSGowner = 'ABC' AND Data LIKE '%ABCDEF%' AND 
([From] ='Customer' AND [To] = 'CSservice') OR ([From] ='CSservice' AND [To] = 'Customer') 

ORDER by Date
4

2 回答 2

2
SELECT Date, From, To, Data 
FROM Ccustomers WITH (NoLock)
WHERE MSGowner = 'ABC' 
AND Data LIKE '%ABCDEF%' 
AND 
(
   ([From] = 'Customer'  AND [To] = 'CSservice') OR 
   ([From] = 'CSservice' AND [To] = 'Customer')
)
ORDER by Date
于 2015-01-27T10:20:44.733 回答
0

您的查询基本上是正确的。但是您必须考虑到and连接比or. 要获得所需的输出,您需要设置括号。

尝试这个:

SELECT Date, [From], [To], Data 
FROM Ccustomers WITH (NoLock)
WHERE MSGowner = 'ABC' 
AND Data LIKE '%ABCDEF%' 
AND (([From] = 'Customer'  AND [To] = 'CSservice') OR ([From] = 'CSservice' AND [To] = 'Customer'))
ORDER BY Date;
于 2015-01-27T10:30:50.087 回答