Skip to content
Advertisement

Pivoting SQL table with crosstab function

I made this query that lists all real estate prices per m2 per year in a city. It works nice yet all years end up in rows, with the prices behind them. I would prefer seeing the years in columns with the price in a cell. Via stackoverflow I found the crosstab function and have experimented with it. Unfortunately I can’t seem to make it work. Would love it if someone could have a look at the query.

Query output example

Desired

Current query

Pivot Attempt

I get this error:

Advertisement

Answer

The second query in crosstab() returns more than 13 rows (exactly 16). You should probably add the condition:

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement