简体   繁体   English

从 SQL 查询中排除组合

[英]Exclude a combination from SQL Query

I have a simple SQL query我有一个简单的 SQL 查询

SELECT NAME, FAMILY_NAME, AGE, SALARY, LOCATION
FROM TABLE
WHERE AGE > 34 and SALARY > 40000

and this works fine.这很好用。 But, I wish to exclude all the entry where NAME = 'ROBERTO' and FAMILY_NAME = 'D_SILVA'.但是,我希望排除 NAME = 'ROBERTO' 和 FAMILY_NAME = 'D_SILVA' 的所有条目。 How can I do this?我怎样才能做到这一点?

I am trying to impose not equal over NAME and FAMILY_NAME but that is excluding all the entries were Name = Roberto or FAMILY_NAME = 'D_SILVA'我试图对 NAME 和 FAMILY_NAME 施加不相等,但排除所有条目为 Name = Roberto 或 FAMILY_NAME = 'D_SILVA'

By using parentheses, you can combine the filters.通过使用括号,您可以组合过滤器。 By nesting these filters (by adding parentheses) shown below and putting the "AND" keyword between the filters, you make sure both conditions have to be true.通过嵌套如下所示的这些过滤器(通过添加括号)并在过滤器之间放置“AND”关键字,您可以确保两个条件都为真。

SELECT [NAME], [FAMILY_NAME], [AGE], [SALARY], [LOCATION]
FROM [dbo].[TABLE]
WHERE [AGE] > 34 
AND [SALARY] > 40000
AND NOT ([NAME] = 'ROBERTO' AND [FAMILY_NAME] = 'D_SILVA')

I recommend reading more about Logical Operator Precedence我建议阅读有关逻辑运算符优先级的更多信息

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM