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 1rrQqL-000aFu-GS for pgsql-sql@arkaria.postgresql.org; Mon, 01 Apr 2024 23:13:34 +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 1rrQqJ-002e4e-Lm for pgsql-sql@arkaria.postgresql.org; Mon, 01 Apr 2024 23:13:32 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rrQqJ-002e4W-CF for pgsql-sql@lists.postgresql.org; Mon, 01 Apr 2024 23:13:32 +0000 Received: from mail-ed1-f46.google.com ([209.85.208.46]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1rrQqD-0002m1-92 for pgsql-sql@lists.postgresql.org; Mon, 01 Apr 2024 23:13:30 +0000 Received: by mail-ed1-f46.google.com with SMTP id 4fb4d7f45d1cf-5688eaf1165so6227282a12.1 for ; Mon, 01 Apr 2024 16:13:24 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712013203; x=1712618003; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=UBwskvk98iF0L7afkSYKnRl+UFWmSZCPDq4ePntB2Ng=; b=ikUZnS+z3HYrU4YREWpNJu7841mPaJNBkxvv9JOFp6UoZEuF25jJ0t5wBZItSka/ZA INhmdX7eQsDsLY2h52EQ/4CjD05+oFFhFvI0+hM/b5nTkitcxiF51TnMuCx/wna6wCb5 4LZHIjOVMXeQVb1tvI/MGZ/YM0sMFjuxJKD01T/SoMb25V67lFdZo6+HTwMRj26QcKIQ 3/Uf2aGl76oBLMN3t4ajPy9SLFW11/8jvfUYIw1pV1uW2GRUwd1sXG9pFGB5/OM3rOIK Zdma6V61X2UcdAKm8a+NVq59XuSxFPwiBP9kPYE51dQwrB6OqOAB5kFfAL0kexBBIT6D 89vA== X-Gm-Message-State: AOJu0YzS+/OYenFJq8tVRcf7BjQf5ofyfHQSRcRLyBPIhPeaqU40FLMm e3D6LjJzy7k0nUDwPMLRrvQUCkbkjwIr3ccpAXNuMJSHx9nUOUJAM2MFyvIuD3neBQ== X-Google-Smtp-Source: AGHT+IEzVg5Os+8YIpdhX/BxI8V9VY6PQsgR+YK6av/PgLA34ZL4MFd91Zkxflab5J5y207AFhl6MQ== X-Received: by 2002:a05:6402:34d4:b0:56b:9b11:9594 with SMTP id w20-20020a05640234d400b0056b9b119594mr10947246edc.2.1712013202668; Mon, 01 Apr 2024 16:13:22 -0700 (PDT) Received: from mail-wm1-f45.google.com (mail-wm1-f45.google.com. [209.85.128.45]) by smtp.gmail.com with ESMTPSA id r1-20020aa7cb81000000b0056dd4bf7660sm1596839edt.52.2024.04.01.16.13.21 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 01 Apr 2024 16:13:21 -0700 (PDT) Received: by mail-wm1-f45.google.com with SMTP id 5b1f17b1804b1-41568096c47so7524935e9.1 for ; Mon, 01 Apr 2024 16:13:21 -0700 (PDT) X-Received: by 2002:adf:e253:0:b0:341:8974:9bae with SMTP id bl19-20020adfe253000000b0034189749baemr7550252wrb.19.1712013201686; Mon, 01 Apr 2024 16:13:21 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Steve Midgley Date: Mon, 1 Apr 2024 16:13:09 -0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: help with a particular multi-table query To: James Cloos Cc: pgsql-sql@lists.postgresql.org Content-Type: multipart/alternative; boundary="000000000000bcd104061511220d" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --000000000000bcd104061511220d Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Mon, Apr 1, 2024 at 3:03=E2=80=AFPM James Cloos wrot= e: > 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? > > I'm a little confused by your SQL, which appears to be incomplete? Could you give some code to create a simple table, populate it with a few sample rows, and then a full SQL query of what you are trying to accomplish? Also include what you get back from your query and what you wish you were getting back, in terms of result sets.. The main thing I'm missing is how t1 and t2 are joined.. I can't see that, so it's hard to understand why your query is not giving you the results you want. Best, Steve --000000000000bcd104061511220d Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable


--000000000000bcd104061511220d--