I have 2 tables
table_a
id b_ref_id qty
52 9 13
53 10 20
54 11 25
table_b
id method date state
9 m1 28/07/16 confirmed
10 m1 29/07/16 done
11 m1 30/07/16 waiting
My desire output
m1 today tomorrow day_after_tomorrow
waiting 13 0 0
confirmed 0 20 0
done 0 0 25
I try with following query but qty is repeat for all
select stock_p.method, stock_p.state,
(select sm.qty
from
table_a sm
join table_b spo on (sm.b_ref_id=spo.id)
where
to_char(spo.date,'YYYY-MM-DD')::date = current_date and ) today_qty,
(select sm.qty
from table_a sm
join table_b spo on (sm.b_ref_id=spo.id)
where
to_char(spo.date,'YYYY-MM-DD')::date = (current_date + 1) ) tomorrow_qty,
(select sm.qty
from table_a sm
join table_b spo on (sm.b_ref_id=spo.id)
where
to_char(spo.date,'YYYY-MM-DD')::date = (current_date + 2)) next_three_qty
from table_a stock_m join table_b stock_p on stock_m.b_ref_id = stock_p.id group by stock_p.method,stock_p.stateenter code here