title: Postgres - converting rows to columns from two tables
body: <p><a href="https://i.stack.imgur.com/EwS1T.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/EwS1T.jpg" alt="enter image description here"></a></p>
  
  <p>The data has been fetched from two tables which have one to may relationship. </p>
  
  <p>Query:</p>
  
  <pre><code> select  temp1.code, temp1.name, temp_dt.item_type, 
      (select item_name from pr_payroll_item where xid = temp_dt.payroll_item_xid 
      ),
      temp_dt.amount from pr_template  temp1, pr_template_detail temp_dt
      where   temp1.xid = temp_dt.parent_xid;
  </code></pre>
  
  <pre class="lang-none prettyprint-override"><code>Item Type 
  0 ear
  1 add
  2 ded
  </code></pre>
  
  <p>I have to display data in this way </p>
  
  <pre><code>code    name    ear    value     add  value     ded  value
  001     Nav     BASIC  1000.00   HR   600.00    PF   50.00
                  FUEL   200.00    
                  Mobile 300.00
  </code></pre>
  
  <p>same for other name  "Me" with mh01
  How can I do this in Postgres? What should be the query to achieve this result set. </p>