Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/oracle/9.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
Sql Case语句还是子查询?_Sql_Oracle - Fatal编程技术网

Sql Case语句还是子查询?

Sql Case语句还是子查询?,sql,oracle,Sql,Oracle,我已经编写了一个select查询,但只有当结果满足某些条件时,我才需要筛选出结果,而不是我仍然希望看到的条件 我已经尝试过包含where case,当x=y,a=b,then=1,否则0 end=1,但这会返回我不想包含的数据 gl.col1, gl.col2, gl.voucher_type, gl.reference_serie Reference_Series, . . . from table1 gl where (case when gl.vouch

我已经编写了一个select查询,但只有当结果满足某些条件时,我才需要筛选出结果,而不是我仍然希望看到的条件

我已经尝试过包含where case,当x=y,a=b,then=1,否则0 end=1,但这会返回我不想包含的数据

 gl.col1,
 gl.col2,
 gl.voucher_type,
 gl.reference_serie Reference_Series,
 .
 .
 .
from table1 gl

where (case 
         when gl.voucher_type = '0' and gl.reference_serie='PUR ORDER' 
                  then 1 ELSE 0 end) =1
原因是如果你看代码,我想排除任何凭证类型为0且参考系列为“PUR ORDER”的内容,但假设有凭证类型为0但参考系列不同,我想查看它。 我知道我的案例中有a=而不是,但这是为了证明我试图找到什么来排除它

我没有任何错误,我只是不确定接下来的步骤,以及案例陈述是否是正确的方法。 谢谢。

在以下情况下,您不需要箱子:

gl.col1, gl.col2, 总账凭证类型, 德国劳埃德船级社参考系列, . . . 摘自表1 gl 其中总账凭证类型='0'和总账参考系列='PUR ORDER' 在以下情况下,您不需要案例:

gl.col1, gl.col2, 总账凭证类型, 德国劳埃德船级社参考系列, . . . 摘自表1 gl 其中总账凭证类型='0'和总账参考系列='PUR ORDER'
通常,您希望避免where子句中的大小写表达式。这里有两个简单的选择:

where not (gl.voucher_type = '0' and gl.reference_serie = 'PUR ORDER')

where gl.voucher_type <> '0' or gl.reference_serie <> 'PUR ORDER'

请注意,这些过滤掉空值-您的表单不过滤空值。如果列具有空值,则可以轻松调整逻辑以处理该问题。

通常,您希望避免where子句中的大小写表达式。这里有两个简单的选择:

where not (gl.voucher_type = '0' and gl.reference_serie = 'PUR ORDER')

where gl.voucher_type <> '0' or gl.reference_serie <> 'PUR ORDER'

请注意,这些过滤掉空值-您的表单不过滤空值。如果列的值为空,则可以轻松调整逻辑以处理该问题。

非常感谢,我已经重新编写了逻辑,并坚持使用简单的where子句。我想我试图把问题复杂化了。再次感谢戈登!非常感谢,我已经重新编写了逻辑,并坚持使用简单的where子句。我想我试图把问题复杂化了。再次感谢戈登!