title: Dynamically creating columns from row data using Select in Bigquery
body: <p><strong>Background</strong></p>
  
  <p>I want to rename my case statement in sql select statement dynamically.</p>
  
  <p>Eg:</p>
  
  <p><code>SELECT (case when id= x.id then x.sums end) x.id
   as  (select id,count(*) sums from table</code>
  <code>group by id) x</code></p>
  
  <p>what i want the output is list of columns created ,with Labels as distinct id's from "id" column.</p>
  
  <p>However,this variable <strong>x.id</strong>  is not dynamically outputing values,rather i get output a single column x.id.</p>
  
  <p>Eg:</p>
  
  <p>Columns in table...</p>
  
  <h2>id---c1----c2</h2>
  
  <hr>
  
  <p>1----x1---x2</p>
  
  <p>2----x2----x3</p>
  
  <p>3----x4----x5</p>
  
  <p>columns expected after running query...</p>
  
  <h2>1-----2----3</h2>
  
  <hr>
  
  <p>but actual o/p column is::</p>
  
  <h2>x.id</h2>
  
  <hr>
  
  <p><strong>Query</strong>
  Any ideas,how to generate columns dynamically using select query,please correct me ,if i am wrong.</p>