In PostgreSQL I have a table country and a table property. One country can have a lot of properties. Each property have a created_at. I need count the properties for each country separating by the year and week. Like an example i have that query for one country.
SELECT
EXTRACT(YEAR FROM created_at) AS yy,
EXTRACT(WEEK FROM created_at) AS week,
COUNT(id) AS country_1
FROM property
WHERE id_country = 1
GROUP BY week, yy
ORDER BY yy, week ASC
The result of that is something like this
yy |week|country_1
---------------
2014|1 |5
2014|2 |1154
2014|3 |769
...
So, i need a result like this
yy |week|country_1|country_2|country_3
----------------------------------------
2014|1 |5 |56 |543
2014|2 |1154 |1234 |432
2014|3 |769 |123 |432
...
Is that possible?, how would be the query?
countryvalues few and known beforehand?