Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/87.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
Teradata SQL而非vs和_Sql_Teradata - Fatal编程技术网

Teradata SQL而非vs和

Teradata SQL而非vs和,sql,teradata,Sql,Teradata,我有一张桌子要分开 原始表是1390K行,我有三个条件A、B和C,我想用它们来拆分表 此查询返回60k行 sel stuff from table where ( A and C) and (B and C) 此查询返回1060k行: sel stuff from table where not ( A and C) and not (B and C) 我的问题是,为什么第二个查询返回1060k行,而不是我预期的1330k行 x和y的对立面是非x或非yx和y的对立面是非x或非y的对立

我有一张桌子要分开

原始表是1390K行,我有三个条件A、B和C,我想用它们来拆分表

此查询返回60k行

sel stuff
from table
where  ( A and C)
and (B and C) 
此查询返回1060k行:

sel stuff
from table
where  not ( A and C)
and not (B and C) 

我的问题是,为什么第二个查询返回1060k行,而不是我预期的1330k行

x和y的对立面是
非x或非y

x和y的对立面是
非x或非y

的对立面是
非x或非y
(A&C)和(B&C)
的对立面不是
!(A&C)及!!(B&C)
但是
!((A&C)和(B&C))

由于没有共享样本数据,我假设您的表中有如下样本数据

a   b   c
---------
0   0   0
1   0   0
0   1   0
0   0   1
1   1   0
0   1   1
1   0   1
1   1   1
您的原始区域查询如下所示

select * from t1
where ( A=1 and C=1)
and (B=1 and C=1);
结果1:

a   b   c
---------
1   1   1
a   b   c
---------
0   0   0
1   0   0
0   1   0
0   0   1
1   1   0
a   b   c
---------
0   0   0
1   0   0
0   1   0
0   0   1
1   1   0
0   1   1
1   0   1
您建议生成与上述查询相反的结果的查询如下所示,它永远不会生成您想要的结果

select * from t1
where not(A=1 and C=1)
and not(B=1 and C=1);
结果2:

a   b   c
---------
1   1   1
a   b   c
---------
0   0   0
1   0   0
0   1   0
0   0   1
1   1   0
a   b   c
---------
0   0   0
1   0   0
0   1   0
0   0   1
1   1   0
0   1   1
1   0   1
以下任何查询都将生成与原始查询相反的结果

select * from t1
where not(( A=1 and C=1)
and (B=1 and C=1));

select * from t1
where A<>1 or B<>1 or C<>1;
从以上查询结果可以看出,
result 1
result 3
完全相反。您可以查看演示

(A&C)和(B&C)
相对的不是
!(A&C)及!!(B&C)
但是
!((A&C)和(B&C))

由于没有共享样本数据,我假设您的表中有如下样本数据

a   b   c
---------
0   0   0
1   0   0
0   1   0
0   0   1
1   1   0
0   1   1
1   0   1
1   1   1
您的原始区域查询如下所示

select * from t1
where ( A=1 and C=1)
and (B=1 and C=1);
结果1:

a   b   c
---------
1   1   1
a   b   c
---------
0   0   0
1   0   0
0   1   0
0   0   1
1   1   0
a   b   c
---------
0   0   0
1   0   0
0   1   0
0   0   1
1   1   0
0   1   1
1   0   1
您建议生成与上述查询相反的结果的查询如下所示,它永远不会生成您想要的结果

select * from t1
where not(A=1 and C=1)
and not(B=1 and C=1);
结果2:

a   b   c
---------
1   1   1
a   b   c
---------
0   0   0
1   0   0
0   1   0
0   0   1
1   1   0
a   b   c
---------
0   0   0
1   0   0
0   1   0
0   0   1
1   1   0
0   1   1
1   0   1
以下任何查询都将生成与原始查询相反的结果

select * from t1
where not(( A=1 and C=1)
and (B=1 and C=1));

select * from t1
where A<>1 or B<>1 or C<>1;

从以上查询结果可以看出,
result 1
result 3
完全相反。您可以查看演示

我看这已经有答案了。然而,我认为值得一提的是一种方法,它不需要您仔细考虑原始查询的逻辑逆是什么

如果第二个查询的目标只是获取第一个查询以外的所有内容,那么第二个查询可能应该是这样的:

sel stuff --This part gets the new records
from table
Minus --This part is the original query and excludes those records
sel stuff
from table
where  ( A and C)
and (B and C) 

我看这已经有了答案。然而,我认为值得一提的是一种方法,它不需要您仔细考虑原始查询的逻辑逆是什么

如果第二个查询的目标只是获取第一个查询以外的所有内容,那么第二个查询可能应该是这样的:

sel stuff --This part gets the new records
from table
Minus --This part is the original query and excludes those records
sel stuff
from table
where  ( A and C)
and (B and C) 

如果
where not((A和C)和(B和C))
任何空值怎么办?@JaydipJ该逻辑不返回任何内容。@jarlh No数据中没有空值。
创建表tb(A布尔值、B布尔值、C布尔值)
添加数据(所有8种组合)。试试你的疑问!如果
where not((A和C)和(B和C))
任何空值怎么办?@JaydipJ该逻辑不返回任何内容。@jarlh No数据中没有空值。
创建表tb(A布尔值、B布尔值、C布尔值)
添加数据(所有8种组合)。试试你的疑问!x或y是否产生了与我在问题中的第二个查询相同的行为,并且确实没有空值?好的,这将非常有助于查看所涉及的实际查询和数据类型。。。并确认您测试的是
不是(a和c)或不是(b和c)
。加上第一个查询的逻辑等价物:
a和c以及b
not x或not y产生了与我在问题中的第二个查询相同的行为,并且确实没有空值?好的,这将非常有助于查看所涉及的实际查询和数据类型。。。并确认您测试的是
不是(a和c)或不是(b和c)
。加上第一次查询的逻辑等价物:
a和c和b
或简单:
其中A1或B1或C1
:-)@dnoeth:是的,一如既往,直观:-)或简单:
其中A1或B1或C1
:-)@dnoeth:是的,一如既往,直观:-)