简体   繁体   中英

Time stamp difference Oracle Query

I have written down a query which is given below to fetch the record from some table.

select g.logtekst DESCRIPTION,g.loggruppe loggroup,TO_CHAR(d.logdato, 'MM-DD-YYYY HH24:MI:SS') logdate 
,d.logtype,d.systemnavn,d.rkibrugernr username,d.psp_id customernumber  
from logbasis_Trans d,logtyper g where d.logtype=g.logtype and d.logdato>Sysdate-720 .

VIR opslag  VIR 03-10-2015 09:53:38 250 NTMF    CONDLOGB    93939393
VIR opslag  VIR 03-10-2015 13:53:52 250 NTMF    CONDLOGB    93939393
Sog opslag  VER 03-10-2015 14:45:30 251 NTMF    CONDOLDB    91919191
Sog opslag  VER 03-10-2015 14:45:31 251 NTMF    CONDOLDB    91919191
Sag opslag  VIR 03-10-2015 14:45:30 251 NTMF    JONDOLDB    95919191
Sog opslag  VJR 03-10-2015 14:45:31 251 NTMF    CFNDOLDB    91719191

This basically list out rows as result from the query.

Now from this I want only such customerNumber (Last Column in this case) which have all the remaining columns same(Log Group Same) but the time difference is <1 Minute between these columns.

In this case the first and second row are multiple entries as time stamp differs by 1 minute and 3-4 columns but not 5 and 6 columns.

Can these query modified to get such data or some manipulation can take place in the excel only remove these type of duplicate records.

use this statement to get the minute differences:

(d.logdato - LAG(d.logdato, 1) OVER (PARTITION BY d.psp_id, d.logtype ORDER BY d.logdato))*24*60 AS diff_min

explanation:
we get logdato from this row and subtract logdato from the preceding row ( LAG 1 ) within a group of records ( OVER ) with same psp_id and logtype ( PARTITION BY ) ordered by logdato ( ORDER BY ), finally we multiply the result to get the minutes from days

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM