Re: Combining data from Temp Tables

Поиск
Список
Период
Сортировка
От Andy Colson
Тема Re: Combining data from Temp Tables
Дата
Msg-id 4F43E43C.40506@squeakycode.net
обсуждение исходный текст
Ответ на Re: Combining data from Temp Tables  (Andy Colson <andy@squeakycode.net>)
Ответы Re: Combining data from Temp Tables  ("David Johnston" <polobo@yahoo.com>)
Список 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 по дате отправления:

Предыдущее
От: Tom Lane
Дата:
Сообщение: Re: Unfamous 'could not read block ... in file "...": read only 0 of 8192 bytes' again
Следующее
От: "David Johnston"
Дата:
Сообщение: Re: Combining data from Temp Tables