从过去两小时内获取Oracle数据库中的数据?

时间:2015-09-16 07:57:38

标签: sql oracle

我想从两小时前和currentime_stamp之间从Oracle数据库中获取数据。我怎么能这样做?

select count(*) as "trn<5",ROUND(avg (RESPONSE_TIME),2) as avr,ssn 
    from db_activity a 
    where a.REQ_TIMESTAMP BETWEEN current_timestamp -2 AND current_timestamp
 group by ssn

2 个答案:

答案 0 :(得分:1)

使用TIMESTAMP时,最好使用INTERVAL

select count(*) as "trn<5",ROUND(avg (RESPONSE_TIME),2) as avr,ssn 
    from db_activity a 
    where a.REQ_TIMESTAMP BETWEEN current_timestamp - INTERVAL '2' HOUR AND current_timestamp
group by ssn

答案 1 :(得分:0)

...where a.REQ_TIMESTAMP  >= (SYSDATE-1/12)