我试图在Oracle查询中使用if。
我需要这样的东西,但是如果能得到帮助,就无法弄清楚语法
select process
from workstep
where workstep_name = 'Manager'
and (performer != 'Test' if end_time =null). <----- this line
这意味着如果endtime = null并且表演者=&#39;测试&#39;然后DONT显示记录;但是,例如,如果endTime不为null并且执行者=&#39; test&#39;然后显示记录。
答案 0 :(得分:1)
你可以这样做
and (end_time is not null or (end_time is null and performer <> 'Test'))
如果我们有这样的数据(左边是表演者,右边是end_time)
'test' - notnulldate
'test' - nulldate
'tttt' - notnulldate
'tttt' - nulldate
this will return all lines except 'test'-nulldate
也许你想要
and ((end_time is not null and performer = 'Test') or (end_time is null and performer <> 'Test'))
将返回
'test'- notnulldate
'tttt'- nulldate
答案 1 :(得分:0)
您可以尝试以下查询:
select process
from workstep
where workstep_name = 'Manager'
and (performer = 'Test' and end_time is not null);
如果要显示end_time不为null的所有执行者,请使用以下版本:
select process
from workstep
where workstep_name = 'Manager'
and end_time is not null;
修改强>:
根据你的澄清,&#34;如果表演者是TEST,那么不要显示NULL结束时间行,但如果表演者不是测试然后DO显示nULL结束时间行&#34;,以下查询会得到你所需数据:
select process
from workstep
where workstep_name = 'Manager'
and (performer <> 'Test' OR end_time is not null);
答案 2 :(得分:0)
您不能在SQL中使用IF,但使用简单的BOOLEAN逻辑可以实现这一点。你只需要同时否定两个条件:
select process
from workstep
where workstep_name = 'Manager'
and not ( performer = 'Test' and end_time is null )
答案 3 :(得分:0)
&#34;表示如果表演者是TEST然后不显示NULL结束时间行,但是如果表演者不是测试然后DO显示nULL结束时间行&#34;
select process
from workstep
where workstep_name = 'Manager'
and ((performer = 'Test' and endtime is not null) or(performer <> 'Test' and endtime is null))
&#34;这意味着如果endtime = null并且表演者=&#39;测试&#39;然后DONT显示记录;但是,例如,如果endTime不为null并且执行者=&#39; test&#39;然后显示记录。&#34;
select process
from workstep
where workstep_name = 'Manager'
and ((endtime is not null and performer <> 'Test' )or(endtime is not null and performer = 'Test'))