title: Pivot table using crosstab and count
body: <p>I have to display a table like this:</p>
  <div class="s-table-container">
  <table class="s-table">
  <thead>
  <tr>
  <th>Year</th>
  <th>Month</th>
  <th>Delivered</th>
  <th>Not delivered</th>
  <th>Not Received</th>
  </tr>
  </thead>
  <tbody>
  <tr>
  <td>2021</td>
  <td>Jan</td>
  <td>10</td>
  <td>86</td>
  <td>75</td>
  </tr>
  <tr>
  <td>2021</td>
  <td>Feb</td>
  <td>13</td>
  <td>36</td>
  <td>96</td>
  </tr>
  <tr>
  <td>2021</td>
  <td>March</td>
  <td>49</td>
  <td>7</td>
  <td>61</td>
  </tr>
  <tr>
  <td>2021</td>
  <td>Apr</td>
  <td>3</td>
  <td>21</td>
  <td>72</td>
  </tr>
  </tbody>
  </table>
  </div>
  <p>Using raw data generated by this query:</p>
  <pre><code>SELECT 
      year,
      TO_CHAR( creation_date, 'Month') AS month,
      marking,
      COUNT(*) AS count 
  FROM invoices
  GROUP BY 1,2,3
  </code></pre>
  <p>I have tried using <code>crosstab()</code> but I got error:</p>
  <pre><code>SELECT * FROM crosstab('
      SELECT 
          year,
          TO_CHAR( creation_date, ''Month'') AS month,
          marking,
          COUNT(*) AS count 
      FROM invoices
      GROUP BY 1,2,3
  ') AS ct(year text, month text, marking text)
  </code></pre>
  <p>I would prefer to not manually type all marking values because they are a lot.</p>
  <blockquote>
  <pre><code>ERROR:  invalid source data SQL statement
  DETAIL:  The provided SQL must return 3 columns: rowid, category, and values.
  </code></pre>
  </blockquote>