How to Transform SQL Queries to Crosstabs in PostgreSQL

A SELECT SQL query retrieves data from a database in a tabular form. The first row, or header row, has the column names, and all the other rows have the data that was retrieved. In a crosstab, the data is condensed and the names of one or more columns are rotated. You can add row and column totals to a crosstab. For example, a list of salesmen’s monthly sales may include the months into the column headers.