2014-04-17 23 views
0

我想在Oracle查询中使用。基于两个互连列的条件结果

我需要这样的事情,但不能图中的语法,如果我能得到帮助

select process 
    from workstep 
where workstep_name = 'Manager' 
    and (performer != 'Test' if end_time =null). <----- this line 

这意味着,如果结束时间= NULL和表演=“测试”然后DONT显示记录;但是,例如,如果endTime不为null,并且执行者='test',则显示该记录。

+0

你想表现出比“测试”表演其他记录呢? –

回答

0

不能使用IF在与Oracle SQL,但是这是可能的简单布尔逻辑。你只需要在同一时间来否定两个条件:

select process 
    from workstep 
where workstep_name = 'Manager' 
    and not (performer = 'Test' and end_time is null) 
1

你能做到这样

and (end_time is not null or (end_time is null and performer <> 'Test')) 

如果我们有这样的DATAS(左边是表演者,右边是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 
+0

这给了我结果endtime不是null和执行者不测试的结果,但我希望看到结果,其中执行者是NOt测试如果结束时间是NULL ..意味着如果执行者是测试然后不显示NULL行结束时间,但是如果执行者不是测试,那么DO显示最后时间行 – junaidp

+0

@junaidp这应该在以下情况下返回数据:end_time不为空,执行者为任何(测试或不测试)+ end_time为空,执行者不测试。这不是发生了什么/你想要什么? –

+0

@junaidp查看如果我明白你想要什么,返回什么回报的例子。 –

0

你可以试试下面的查询:

select process 
from workstep 
where workstep_name = 'Manager' 
and (performer = 'Test' and end_time is not null); 

如果你想显示所有的表演者,其中END_TIME不为空,然后使用以下版本:

select process 
from workstep 
where workstep_name = 'Manager' 
and end_time is not null; 

编辑

根据你的说明,“如果演员是测试,那么不显示NULL结束时间的行,但如果演员不测试,然后DO显示最后的结束时间行”,下面的查询会得到你所需要的数据:

select process 
from workstep 
where workstep_name = 'Manager' 
and (performer <> 'Test' OR end_time is not null); 
+0

如果PERFORMER是'blah'和END_TIME不为空会发生什么? – Ben

+0

然后记录将不会显示。只有PERFORMER为Test时,此查询才会显示。 –

+0

我想查看结果,其中执行者是NOt测试如果结束时间是NULL ..意思是如果执行者是测试,那么不显示NULL结束时间的行,但是如果执行者不测试然后DO显示最后结束时间行 – junaidp

0

“意味着,如果表演是先测试后不显示的NULL结束该行的时间,但是,如果表演者不可考则确实显示空结束时间排“

select process 
from workstep 
where workstep_name = 'Manager' 
and ((performer = 'Test' and endtime is not null) or(performer <> 'Test' and endtime is null)) 

”这意味着,如果结束时间= NULL和表演=‘测试’然后DONT显示的记录;但如果,例如,结束时间是不是null,表演=‘测试’,那么SHOW记录。”

select process 
from workstep 
where workstep_name = 'Manager' 
and ((endtime is not null and performer <> 'Test')or(endtime is not null and performer = 'Test')) 
+0

这个endtime不为null并且执行者不测试的结果给我,但是我希望看到执行者在NOt测试中的结果如果结束时间是NULL ..意思是如果执行者是TEST那么不显示NULL行结束时间,但是如果演员不是测试,那么DO显示最后的时间行 – junaidp