我在连接查询中使用了完全外连接条件来连接两个表,示例代码如下所示
select * from(
select TO_CHAR(ROUND(col11)) as today1,TO_CHAR(ROUND(col12)) as today2 from T1
full outer join
select TO_CHAR(ROUND(col21)) as yes1,TO_CHAR(ROUND(col22)) as yes2 from T2
) MAIN
where MAIN.today1<>0 and MAIN.today2<>0 and MAIN.yes1<>0 and MAIN.yes2<>0
预期的样本输出如下
today1 today2 yes1 yes2
somevalue somevalue null null
null null some value somevalue
somevalue somevalue somevalue some value
0 0 0 0
我正在尝试使用上面的where子句删除具有全部 值的行,但输出为双倍,并且还使用零值appeges进行排序。我能知道我哪里出错了。任何帮助非常感谢。
答案 0 :(得分:0)
尝试删除具有全零值的行
使用:
AND NOT ( MAIN.today1=0 and MAIN.today2=0 and MAIN.yes1=0 and MAIN.yes2=0 )
可以使用De Morgan的定律进行转换:
===&gt; https://en.wikipedia.org/wiki/De_Morgan%27s_laws进入:
AND ( NOT MAIN.today1=0 OR NOT MAIN.today2=0 OR NOT MAIN.yes1=0 OR NOT MAIN.yes2=0 )
可以进一步简化为:
AND ( MAIN.today1<>0 OR MAIN.today2<>0 OR MAIN.yes1<>0 OR MAIN.yes2<>0 )
注意:如果您还想获得NULL值,则必须使用IS NULL
运算符:
where ( MAIN.today1<>0 OR MAIN.today1 IS NULL )
and ( MAIN.today2<>0 OR MAIN.today2 IS NULL )
and ( MAIN.yes1<>0 OR MAIN.yes1 IS NULL )
and ( MAIN.yes2<>0 OR MAIN.yes2 IS NULL )