title: oracle : Dynamic column name
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/9582218/oracle-rows-to-column-transformation">Oracle Rows to Column Transformation</a>  </p>
  </blockquote>
  
  
  
  <p>My real problem is just like this but has many tables related to each other. So, I just created a example, so assuming if this gets solved, my real problem gets solved.
  Here are my tables :</p>
  
  <p><strong>tbl_products</strong></p>
  
  <pre><code>    tp_id | tp_name 
  
       1      apple
  
       2      mango
  
       3      pineapple
  </code></pre>
  
  <p><strong>tbl_sales</strong></p>
  
  <pre><code>    ts_id | ts_location | ts_tp_id | ts_sales
  
         1        NY              2           5
         2        LN              2           10  
         3        QL              1           25          
         4        QL              3           20
         5        LN              3           35
         6        NY              3           50
         7        NY              1           100
  </code></pre>
  
  <p>If I have these two tables, tbl_products and tbl_sales, how to create a query that has a dynamic columns like this :</p>
  
  <pre><code> sales_location | apple | mango | pineapple 
        NY           100       5        50
  </code></pre>
  
  <p>where apple, mango and pineapple should have the total number of sales according to location</p>