I want to create a pivot table view showing month on month sum of bookings for every travel_mode.
Table 1 bookings - timestamp, bookings, provider_id Table 2 providers - provider_id, travel_mode
Pivot table function and crosstab functions are not to be used to do this exercise. I want to either use joins or some other function.
I don't understand the issue with this query I am trying to run, it shows "relation x does not exist"
SELECT c.month, train.amount, bus.amount, air.amount
FROM (SELECT x.month
FROM (SELECT to_char(date_,'month') as month, travel_mode, sum(bookings) as amount
from bookings as b
join providers as p
on b.provider_id=p.provider_id
group by month, travel_mode) x
group by x.month
) c
JOIN x train ON c.month = train.month AND train.amount = 'train'
JOIN x bus ON c.month = bus.month AND bus.amount = 'bus'
JOIN x air ON c.month = air.month AND air.amount = 'air'
;