Re: Combining data from Temp Tables - Mailing list pgsql-general

From Andy Colson
Subject Re: Combining data from Temp Tables
Date
Msg-id 4F43E43C.40506@squeakycode.net
Whole thread Raw
In response to Re: Combining data from Temp Tables  (Andy Colson <andy@squeakycode.net>)
Responses Re: Combining data from Temp Tables
List pgsql-general
how about

select date, ln, mbrid, ds, (
   select sum(ds) from t2
   where t2.date >= t1.date and t2.date <= t1.date + '5 days'::interval
   and t1.ln = t2.ln
   and t1.mbrid = t2.mbrid)
from t1

That'll give you both the plus and minus (in two different columns), but
it might sum up the same row from table2 multiple times so I'm not sure
its correct.

And I'm not sure the date range is correct.

Another way to look at the same thing:

select date, ln, mbrid, dsplus - dsminus
from (
  select date, ln, mbrid, ds as dsplus, (
   select sum(ds) from t2
   where t2.date >= t1.date and t2.date <= t1.date + '5 days'::interval
   and t1.ln = t2.ln
   and t1.mbrid = t2.mbrid) as dsminus
  from t1
) as x
where dsplus - dsminus <> 0



Totally guessing here.

-Andy





pgsql-general by date:

Previous
From: Tom Lane
Date:
Subject: Re: Unfamous 'could not read block ... in file "...": read only 0 of 8192 bytes' again
Next
From: "David Johnston"
Date:
Subject: Re: Combining data from Temp Tables