2012-02-21 28 views
0

如何在此查詢中獲取180秒以上的Diff_In_Secs?如何在此SQL查詢中獲取值大於3分鐘的行?

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

包裹查詢與選擇:

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 
相關問題