Re: Electricity bill

From: "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>
To: stercor(at)gmail(dot)com
Cc: pgsql-sql <pgsql-sql(at)lists(dot)postgresql(dot)org>
Subject: Re: Electricity bill
Date: 2022-06-08 01:47:17
Message-ID: CAKFQuwaY-zeoWkJwqDP6TDZnowdif2AZsT28+-SA2OWc8KXKTA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

On Tue, Jun 7, 2022 at 6:39 PM Theodore M Rolle, Jr. <stercor(at)gmail(dot)com>
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.

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Theodore M Rolle, Jr. 2022-06-08 01:48:59 Fwd: Electricity bill
Previous Message Jonathan Katz 2022-06-08 01:42:27 Re: Electricity bill