title: Create a pivot table with PostgreSQL
body: <p>Suppose I have a table in Postgres called <code>listings</code> that looks like this:</p>
  
  <pre><code>id    neighborhood    bedrooms    price
  1     downtown        0           256888
  2     downtown        1           334000
  3     riverview       1           505000
  etc.
  </code></pre>
  
  <p>How do I write a crosstab query that shows the average price per bedrooms as the columns and neighborhoods as the rows?</p>
  
  <p>The output of the query should look something like this (numbers are made up, columns are the bedrooms):</p>
  
  <pre><code>            0       1       2       3
  riverton    250000  300000  350000  -
  downtown    189000  325000  -       450000
  </code></pre>