Re: help with a particular multi-table query

From: Steve Midgley <science(at)misuse(dot)org>
To: James Cloos <cloos(at)jhcloos(dot)com>
Cc: pgsql-sql(at)lists(dot)postgresql(dot)org
Subject: Re: help with a particular multi-table query
Date: 2024-04-01 23:13:09
Message-ID: CAJexoS+gyE6-GqRqwZ+e79dX0JSi8KOYKLFiaJNVC1L0mNMhTA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

On Mon, Apr 1, 2024 at 3:03 PM James Cloos <cloos(at)jhcloos(dot)com> wrote:

> 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

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Nazneen Mulani 2024-04-02 09:19:36 postgres is slow on windows
Previous Message James Cloos 2024-04-01 22:03:26 help with a particular multi-table query