What is Crosstab Query?
A query that transforms rows into columns, creating a pivot table view of aggregated data.
Crosstab (pivot) queries rotate data from rows to columns. In PostgreSQL, the tablefunc extension provides the crosstab() function. This is useful for reporting — turning monthly sales rows into columns for each month.
Alternative approaches include CASE expressions with GROUP BY for manual pivoting. Crosstab queries simplify dashboard reporting, time-series analysis, and comparative data views.