PostgreSQL crosstab() alternative with CASE and aggregates
问题 I want to create a pivot table view showing month on month sum of bookings for every travel_mode . Table bookings : timestamp , bookings , provider_id Table providers : provider_id , travel_mode Pivot table function and crosstab functions are not to be used to do this. So I am trying to use JOIN and CASE. Following is the query: SELECT b.month, (CASE WHEN p.travel_mode=train then b.amount end)train, (CASE WHEN p.travel_mode=bus then b.amount end)bus, (CASE WHEN p.travel_mode=air then b.amount