Search Postgresql Archives

Re: Combining data from Temp Tables

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 




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





--
Sent via pgsql-general mailing list (pgsql-general@xxxxxxxxxxxxxx)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux