0

我有下面的订单表,我想在今天的日期和时间(美国 17:00)检索那些不在订单状态“已处理”和 cacel)状态“已取消”的记录。请帮我完成我的问题。

order id  ordername order_status  cancel_status  order_time           cancel_time 
==============================================================================================    
1         Iphone    processed     cancelled      10/08/2012 16:00:00  10/08/2012 16:00:00        
2         samsung   notprocessed  null           null                 null        
3         nokia     processed     cancelled      10/08/2012 16:00:00  10/08/2012 17:00:00    
4         motorola  notprocessed  null           null         null    
5         HTC       processed     null           10/08/2012 17:00:00  null

我尝试了以下方式,但没有返回任何记录。请帮助我。

SELECT * 
FROM 
    order 
WHERE 
    to_char(order_time,'YYYYMMDD HH24:MI:SS')>To_char(sysdate,YYYYMMDD) || ' '|| '17:00:00' 
and to_char(cancel_time,'YYYYMMDD HH24:MI:SS')>To_char(sysdate,YYYYMMDD) || ' '|| '17:00:00' 
and order_time is null 
and cancel_time is null
4

2 回答 2

0
Select * from order 
where 
( to_char(order_time,'YYYYMMDD HH24:MI:SS')>To_char(sysdate,YYYYMMDD) || ' '|| '17:00:00' 
or order_time is null ) 
and ( to_char(cancel_time,'YYYYMMDD HH24:MI:SS')>To_char(sysdate,YYYYMMDD) || ' '|| '17:00:00' 
or cancel_time is null )
于 2012-10-08T18:34:50.567 回答
0
select * 
from order o 
where o.order_status != 'processed' 
  and o.cancel_status = 'cancelled' 
  and o.order_time < (trunc(sysdate) + 17/24) 
  and o.cancel_time < (trunc(sysdate) + 17/24)
于 2012-10-08T18:35:16.617 回答