self join for history analyzis

From: Rafał Pietrak <rafal(at)zorro(dot)isa-geek(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: self join for history analyzis
Date: 2013-01-26 12:32:04
Message-ID: 5103CCC4.5030900@zorro.isa-geek.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hello the list,

For some time now, I'm struggling with a problem of self join of a table:

I have a usage recording table: CREATE TABLE readings(tm timestamp,
bytesin int, bytesout int);

The readouts are made "occasionally" - the timespan between the readouts
are not very precise, but there is a lot of those readouts.

I need to make a self join of that table to analyze the bandwidth usage
e.g.: when presenting data, for every readout I need to compute the
difference between it and the one immediately preceding it, and divide
that by respective measurement interval.

Initially I've put an additional column with a serial into the readouts
table, and did a join on (p.serial = n.serial+1); but that had an
occasional glitch, when serial actually skipped a value. So I'm trying
to work out a more resiliant/general solution. So far to no avail.

Is there an "sql-idiom" (receipt?) to do such join? the better if
without the spurious seiral column.

Thenx

-R

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Alban Hertroys 2013-01-26 13:49:14 Re: self join for history analyzis
Previous Message Gavan Schneider 2013-01-26 05:07:36 Re: Throttling Streamming Replication