Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/71.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在SQLWHERE子句中筛选这些特定行?_Sql_Database_String_Where Clause_Google Cloud Sql - Fatal编程技术网

如何在SQLWHERE子句中筛选这些特定行?

如何在SQLWHERE子句中筛选这些特定行?,sql,database,string,where-clause,google-cloud-sql,Sql,Database,String,Where Clause,Google Cloud Sql,假设我有这张桌子: ID | A | B 1 | blue | 2 2 | red | 2 3 | blue | 1 4 | red | 1 假设我想要A列的所有内容,除了蓝色对应于B列中的A2 因此,基本上,结果应该给出第2、3、4行,而不包括1行 到目前为止,我有这样的想法: SELECT * FROM Table WHERE A IN ('blue','red') 同样,对于上面的查询,它将包括第1行,因为它有蓝色。出于意图

假设我有这张桌子:

ID |     A  |  B
1  |  blue  |  2
2  |  red   |  2
3  |  blue  |  1
4  |  red   |  1
假设我想要A列的所有内容,除了蓝色对应于B列中的A2

因此,基本上,结果应该给出第2、3、4行,而不包括1行

到目前为止,我有这样的想法:

SELECT *
FROM 
   Table
WHERE
   A IN ('blue','red')
同样,对于上面的查询,它将包括第1行,因为它有蓝色。出于意图和目的,让我们假设在A列中有不止这两种颜色,但我只需要这两种,所以我需要第一个WHERE语句。当B列为2时,告诉它不包括A列的蓝色最简单的方法是什么

提前谢谢

当B列为2时,告诉它不包括A列的蓝色最简单的方法是什么

这看起来像:

select * 
from mytable
where a in ('blue', 'red') and not (a = 'blue' and b = 2)
您也可以将其表述为:

where a = 'red' or (a = 'blue' and b <> 2)
其中a='red'或(a='blue'和b2)
当B列为2时,告诉它不包括A列的蓝色最简单的方法是什么

这看起来像:

select * 
from mytable
where a in ('blue', 'red') and not (a = 'blue' and b = 2)
您也可以将其表述为:

where a = 'red' or (a = 'blue' and b <> 2)
其中a='red'或(a='blue'和b2)

你能为你的问题提供示例输出吗?只需拿出示例表中的第一行,这就是我应该看到的内容。你能为你的问题提供示例输出吗?只需拿出示例表中的第一行,这就是我应该看到的内容