Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nyknR-00045n-A3 for pgsql-sql@arkaria.postgresql.org; Wed, 08 Jun 2022 01:47:45 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1nyknP-0007r1-GI for pgsql-sql@arkaria.postgresql.org; Wed, 08 Jun 2022 01:47:43 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nyknP-0007qs-0j for pgsql-sql@lists.postgresql.org; Wed, 08 Jun 2022 01:47:43 +0000 Received: from mail-ej1-x635.google.com ([2a00:1450:4864:20::635]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1nyknI-0007sp-FC for pgsql-sql@lists.postgresql.org; Wed, 08 Jun 2022 01:47:41 +0000 Received: by mail-ej1-x635.google.com with SMTP id o7so5278168eja.1 for ; Tue, 07 Jun 2022 18:47:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=CjjDSLywONUq/zB9hoqkJCY4651df0tsKCUkVemCmw4=; b=aJTSVRZFbbXypzeNyrxOYPBVGdJ3Ec4AlWnEIrZ96cSsmSsDd8iOyTLoh/2Jbuq+Vg V/SmC1QrktWt/KHd0Z60do2UtUXvwkUzzN16PICGyLSv1lKd2jp+sExzR4qcZf2eJe2P twLzR+b4xxHPQ4dU21lMdjTPmsOWBZdGPxCOUFG83lIBWTrUnVfQGyrGIIATK6BhObfZ rff+V4VCM6ECzI+D+O+y6YYyzqH2U1ox+PYUkHPgTVdPR+yMnKae4WUMYfNfRWjPGB+q 3QbB8/i4qapctbxJD7YjcspQeL7W4s4Ad1M/xYHnEJbVacHl0cUL06l+DCdzmPN9BV2q ukMg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=CjjDSLywONUq/zB9hoqkJCY4651df0tsKCUkVemCmw4=; b=rwC5tRoUFGVJiyxkdFaEhNKDZEXu6M0K2w6aABaFXMGmccA48ur9zgJoJbx5MletfE KNYCFv/NZOvNnXwxcAMqSAX6/d6EcVWp/8SgcWcPF2dTKcdwX7Pk0vc6xE7AuvTws9N6 ePbrDDcheokbXYi3LfEKxJH1TSVelay+qPb8C/iaG7PTmip98vsyo7ni/HUstzYwpSM0 lHaISmbQ3W41YGKfU/azDROrUruxetKLQX4/83GF6m1xungSkfV5Vh1jXcO2E3P29eVv X3odSkH/3k+hCZEnwQKYfm2ePo9OLHYQbaR0637IxXcUs+Ege79SIJCwifCwOQXLoqdt 4pHA== X-Gm-Message-State: AOAM5307VOTabXgGb5NN7atQQasz/RY1NIgxwzy6mRrN27o7qadOQlsp G8dwzzpH25DsECiXamzkuBkXuXyzWnCq0qPHNkmhjBXm X-Google-Smtp-Source: ABdhPJyKFoca6LWz5gcFmOxLtJCwYvDPlLkEpQCggb7XCI2MoLMNSxuuhCyTHdsyldbcAn1tRSvQ28Aavyqf/16aMzA= X-Received: by 2002:a17:906:3e8e:b0:70f:9a81:8218 with SMTP id a14-20020a1709063e8e00b0070f9a818218mr21608922ejj.525.1654652854893; Tue, 07 Jun 2022 18:47:34 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: "David G. Johnston" Date: Tue, 7 Jun 2022 18:47:17 -0700 Message-ID: Subject: Re: Electricity bill To: stercor@gmail.com Cc: pgsql-sql Content-Type: multipart/alternative; boundary="000000000000a4814c05e0e5e39d" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --000000000000a4814c05e0e5e39d Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Tue, Jun 7, 2022 at 6:39 PM Theodore M Rolle, Jr. wrote: > I'm putting in YYYY-MM-DD dates of electricity bills and would like to no= t > have starting and ending dates in the same row. Only ending date. > Will someone show me the SQL to compute the months=E2=80=99 usage? This r= equires > 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. --000000000000a4814c05e0e5e39d Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
On Tue, Jun 7, 2022 at 6:39 PM Theodore M Rolle, Jr. <<= a href=3D"mailto:stercor@gmail.com">stercor@gmail.com> wrote:=
I'm putting in YYYY-MM-DD dates of = electricity bills and would like to not have starting and ending dates in t= he same row. Only ending date.
Will someone show me the SQ= L to compute the months=E2=80=99 usage? This requires retrieving two rows t= o compute the number of days...

Y= ou 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.
--000000000000a4814c05e0e5e39d--