Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rrPkj-000SS8-76 for pgsql-sql@arkaria.postgresql.org; Mon, 01 Apr 2024 22:03:41 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1rrPkh-0029at-JK for pgsql-sql@arkaria.postgresql.org; Mon, 01 Apr 2024 22:03:40 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rrPkh-0029ak-9n for pgsql-sql@lists.postgresql.org; Mon, 01 Apr 2024 22:03:39 +0000 Received: from ore.jhcloos.com ([192.40.56.151]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rrPkb-00031T-00 for pgsql-sql@lists.postgresql.org; Mon, 01 Apr 2024 22:03:35 +0000 Received: from oxygen.jhcloos.org (oxygen [192.168.1.8]) by ore.jhcloos.com (Postfix) with ESMTP id 0DD111E5AF for ; Mon, 1 Apr 2024 22:03:27 +0000 (UTC) Received: from nitrogen.jhcloos.org (nitrogen.jhcloos.org [192.168.1.7]) by oxygen.jhcloos.org (Postfix) with ESMTP id 43BDB840406 for ; Mon, 1 Apr 2024 22:03:26 +0000 (UTC) Received: by nitrogen.jhcloos.org (Postfix, from userid 500) id 3984E15F74; Mon, 01 Apr 2024 22:03:26 +0000 (-00) From: James Cloos To: pgsql-sql@lists.postgresql.org Subject: help with a particular multi-table query User-Agent: Gnus/5.13 (Gnus v5.13) Face: iVBORw0KGgoAAAANSUhEUgAAABAAAAAQAgMAAABinRfyAAAACVBMVEX///8ZGXBQKKnCrDQ3 AAAAJElEQVQImWNgQAAXzwQg4SKASgAlXIEEiwsSIYBEcLaAtMEAADJnB+kKcKioAAAAAElFTkSu QmCC Copyright: Copyright 2024 James Cloos OpenPGP: 0x997A9F17ED7DAEA6; url=https://jhcloos.com/public_key/0x997A9F17ED7DAEA6.asc OpenPGP-Fingerprint: E9E9 F828 61A4 6EA9 0F2B 63E7 997A 9F17 ED7D AEA6 Date: Mon, 01 Apr 2024 18:03:26 -0400 Message-ID: Lines: 26 MIME-Version: 1.0 Content-Type: text/plain List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk I'm attempting a three column select from two tables, where only a single column from each of the tables matters. t1.date and t2.time are both timestamptz. I want the three columns to be: t1.date::date t1.date - lag(t1.date,1) over (order by date asc) days, and count(t2.time) from the interval lag(t1.date,1) and t1.date. but that syntax of course fails do to the placements I've tried for thae between. I tried a sub-query but got what looked like an outer join. I want exactly count(*) from t1 rows in the result. What trick am I missing? -JimC -- James Cloos OpenPGP: https://jhcloos.com/0x997A9F17ED7DAEA6.asc