title: sql transformation - rows to column
body: <p>i have been trying to solve this one <a href="https://i.stack.imgur.com/y47E7.png" rel="nofollow noreferrer">image</a></p>
  <p>my initial idea is like this</p>
  <pre><code>select name,
      CASE
      when count(name) = 1 then get first distinct value
      when count(name) = 2 then get first distinct value
      else get first distinct value
      END  as val1,
      CASE
      when count(name) = 1 then null
      when count(name) = 2 then get second distinct value
      else get second distinct value
      END as val2,
      CASE
      when count(name) = 1 then null
      when count(name) = 2 then null
      else get third distinct value
      END as val3
  into desired_table
  from source_table
  group by name
  </code></pre>
  <p>is my attempt feasible? if so, how do i access the first, second and third distinct values?</p>