Re: calculate time diffs across rows with single timestamp - Mailing list pgsql-sql

From Rodrigo De León
Subject Re: calculate time diffs across rows with single timestamp
Date
Msg-id 1181753515.419178.63440@j4g2000prf.googlegroups.com
Whole thread Raw
In response to calculate time diffs across rows with single timestamp  (Bob Singleton <bsingleton@ibss.net>)
Responses Re: calculate time diffs across rows with single timestamp  (Bob Singleton <bsingleton@ibss.net>)
List pgsql-sql
On Jun 13, 11:17 am, bsingle...@ibss.net (Bob Singleton) wrote:
> Any suggestions on how I can build a result set that would return
>
> ASSET 001 AAA 1:00 (1 hour)
> ASSET 001 BBB 0:10 (10 minutes)
> ASSET 001 CCC 0:08 (8 minutes)
> ASSET 001 DDD {difference between timestamp and now()}
> ASSET 002 AAA 0:03 (3 minutes)
> ASSET 002 BBB {difference detween timestamp and now()}
> ASSET 003 AAA{diff between timestamp and now()}

SELECT
TYPE, ID, STATUS
, (COALESCE((SELECT MIN(DATETIME) FROM STATUSLOGWHERE TYPE = S.TYPE AND ID = S.ID AND DATETIME > S.DATETIME),
NOW()::TIMESTAMP)- DATETIME) AS DURATION
 
FROM STATUSLOG S
ORDER BY TYPE, ID, STATUS



pgsql-sql by date:

Previous
From: Bob Singleton
Date:
Subject: calculate time diffs across rows with single timestamp
Next
From: Bob Singleton
Date:
Subject: Re: calculate time diffs across rows with single timestamp