title: How to pivot in postgresql
body: <p>I have table like following,and I would like to transform them.</p>
  <pre><code>year month week type count
  2021  1     1    A    5
  2021  1     1    B    6
  2021  1     1    C    7
  2021  1     2    A    0
  2021  1     2    B    8
  2021  1     2    C    9
  </code></pre>
  <p>I'd like to pivot like following.</p>
  <pre><code>year month week  A  B  C
  2021  1     1    5  6  7
  2021  1     2    0  8  9
  </code></pre>
  <p>I tried like following statement, but it returned a lot of null columns.
  And I wonder I must add columns one by one when new type will be added.</p>
  <pre><code>select
      year,
      month,
      week,
      case when type in ('A') then count end as A,
      case when type in ('B') then count end as B,
      case when type in ('C') then count end as C,
      
  from
     table
  </code></pre>
  <p>If someone has opinion, please let me know.
  Thanks</p>