Мне нужно получить сумму количеств после и до даты из таблицы.
Вот что я пробовал:
select location_id, t1.product_id, sum(t1.quantity) as open,
t2.product_id as t2_p,sum(t2.quantity) as current
from (select id, location_id, product_id, quantity
from stock_history
where date::date<='2018-09-23') t1
FULL OUTER JOIN (select id, product_id, quantity
from stock_history
where date::date>'2018-09-23') t2
ON t1.product_id = t2.product_id
group by location_id, t1.product_id;