Posted on 4th May 2025|1828 views
How to create pivot without crosstab in PostgreSQL?
Posted on 4th May 2025| views
No, you cannot create a Pivot table in PostgreSQL without using crosstab function as you have to use a tablefunc module for a required database.
Raw data using crosstab() function before Pivoting:
Student |
Subject |
Evaluation_result |
Smith, John |
Music |
7.0 |
Smith, John |
Maths |
4.0 |
Smith, John |
History |
9.0 |
Smith, John |
Language |
7.0 |
Smith, John |
Geography |
9.0 |
Gabriel, Peter |
Music |
2.0 |
Gabriel, Peter |
Maths |
10.0 |
Gabriel, Peter |
History |
7.0 |
Gabriel, Peter |
Language |
4.0 |
Gabriel, Peter |
Geography |
10.0 |
After Pivoting table:
Student |
Geography |
History |
Language |
Maths |
Music |
Gabriel, Peter |
10.0 |
7.0 |
4.0 |
10.0 |
2.0 |
Smith, John |
9.0 |
9.0 |
7.0 |
4.0 |
7.0 |