I have a table with data in a following format
region gender age_group population
Dallas M 1 200
Dallas F 1 500
NY M 1 320
NY F 1 310
Dallas M 2 300
Dallas F 2 600
NY M 2 400
NY F 2 800
I'm looking for the best query to output my data in the following format
region/age_group 1 2
Gender M F M F
Dallas 200 500 300 600
NY 320 310 400 800
my query returns only the top colum and region. Not sure how to sub divide the top colum into genders as appearing above
SELECT distinct (region), a.group_one, b.group_two
FROM city_populations c
LEFT JOIN city_populations AS a ON a.age_group=1 AND c.age_group=a.age_group
LEFT JOIN city_populations AS b ON b.age_group=2 AND c.age_group=a.age_group