如何在此SQL查询中获取值超过3分钟的行?

时间:2012-02-21 05:14:09

标签: sql oracle

如何在此查询中将Diff_In_Secs提升180秒以上?

select trunc(a.RECEIVED_TS) day, 
       to_char(avg(extract(minute from b.RECEIVED_TS - a.RECEIVED_TS)*60 + extract(second from b.RECEIVED_TS - a.RECEIVED_TS)), '999.99') Diff_In_Secs, 
       count(*)
  from nps_request a, 
       nps_reply b
 where a.id = b.ID
   and a.RECEIVED_TS > trunc(sysdate) - 10
   and b.target_id is not null
   and b.RECEIVED_TS is not null
group by trunc(a.RECEIVED_TS)
order by trunc(a.RECEIVED_TS) desc;

1 个答案:

答案 0 :(得分:1)

使用select:

包装查询
SELECT * FROM ( 
    select trunc(a.RECEIVED_TS) day, to_char(avg(extract(minute from b.RECEIVED_TS - a.RECEIVED_TS)*60 + extract(second from b.RECEIVED_TS - a.RECEIVED_TS)), '999.99') Diff_In_Secs, count(*)
    from nps_request a, nps_reply b
    where a.id = b.ID
    and a.RECEIVED_TS > trunc(sysdate) - 10
    and b.target_id is not null
    and b.RECEIVED_TS is not null
    group by trunc(a.RECEIVED_TS)
    order by trunc(a.RECEIVED_TS) desc;
) AS A WHERE A.Diff_In_Secs > 180