CROSSTAB

PostgreSQL CROSSTAB

PIVOT and UNPIVOT Operators