public inbox for [email protected]  
help / color / mirror / Atom feed
From: David G. Johnston <[email protected]>
To: [email protected]
Cc: pgsql-sql <[email protected]>
Subject: Re: Electricity bill
Date: Tue, 7 Jun 2022 18:47:17 -0700
Message-ID: <CAKFQuwaY-zeoWkJwqDP6TDZnowdif2AZsT28+-SA2OWc8KXKTA@mail.gmail.com> (raw)
In-Reply-To: <CAPDmd-CjfhW5pSkthOGmb1rDpznDWYOetrhVh1gcquwQM9n5eA@mail.gmail.com>
References: <CAPDmd-CjfhW5pSkthOGmb1rDpznDWYOetrhVh1gcquwQM9n5eA@mail.gmail.com>

On Tue, Jun 7, 2022 at 6:39 PM Theodore M Rolle, Jr. <[email protected]>
wrote:

> I'm putting in YYYY-MM-DD dates of electricity bills and would like to not
> have starting and ending dates in the same row. Only ending date.
> Will someone show me the SQL to compute the months’ usage? This requires
> retrieving two rows to compute the number of days...
>

You can use a window function called lead (or lag) to retrieve a value from
the next (previous) row and associate it with the current row.

David J.


view thread (5+ messages)  latest in thread

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: [email protected]
  Cc: [email protected], [email protected], [email protected]
  Subject: Re: Electricity bill
  In-Reply-To: <CAKFQuwaY-zeoWkJwqDP6TDZnowdif2AZsT28+-SA2OWc8KXKTA@mail.gmail.com>

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

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