pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Rodrigo De León <rdeleonp@gmail.com>
To: pgsql-sql@postgresql.org
Subject: Re: calculate time diffs across rows with single timestamp
Date: Wed, 13 Jun 2007 16:51:55 -0000
Message-ID: <1181753515.419178.63440@j4g2000prf.googlegroups.com> (raw)
In-Reply-To: <467018B0.30108@ibss.net>
References: <467018B0.30108@ibss.net>

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 STATUSLOG
	WHERE TYPE = S.TYPE AND ID = S.ID AND DATETIME > S.DATETIME)
	, NOW()::TIMESTAMP
	) - DATETIME) AS DURATION
FROM STATUSLOG S
ORDER BY TYPE, ID, STATUS




view thread (3+ messages)  latest in thread

Message-ID: <1181753515.419178.63440@j4g2000prf.googlegroups.com>
Permalink:  ../1181753515.419178.63440@j4g2000prf.googlegroups.com/
Also on:    postgresql.org/message-id/1181753515.419178.63440@j4g2000prf.googlegroups.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: rdeleonp@gmail.com
  Subject: Re: calculate time diffs across rows with single timestamp
  In-Reply-To: <1181753515.419178.63440@j4g2000prf.googlegroups.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox