MySQL select dynamic row values as column Name
<p>I have the following details in my table</p>

<h1>stock table</h1>

<pre><code>id sale stock item_code branch
1   0    200   abc       A
2   100  200   abc       A
3   0    200   def       B
4   100  200   def       B
5   0    200   xyz       B
6   100  200   xyz       A
</code></pre>

<p>And, her is my expected output:</p>

<pre><code>item_code    A-sale  A-stock     B-sale   B-stock 
abc           100      400       null      null  
def           null    null        100       400
xyz           100      200         0        200
</code></pre>

<p>How can I manage to get this output from the stock table?</p>