0

I have table localbanya ,I wanted to do pivoting of its column, Here is my table structure

Billingid    prod_id     qty
  1            11         2
  1            22         5
  2            11         1
  2            22         3
  2            33         4
  3            11         2
  3            22         1

I'm expecting something like this

Billinid    11   22   33    Total
   1        2     5    0    2+5+0
   2        1     3    4    1+3+4
   3        2     1    0    2+1+0

I have tried this but unable to get the desired result

SELECT billingid,GROUP_CONCAT(qty) 
FROM localbanya
GROUP BY billingid; 

please help, Thanks in advance

Deepesh
  • 820
  • 1
  • 14
  • 32
  • Isn't qty an integer column? Put case expressions the the select list, one for each prod_id you're interested in. – jarlh Feb 24 '16 at 08:01
  • I'm interested in the entire values of prod_id column – Deepesh Feb 24 '16 at 08:02
  • What if billingid 44 suddenly shows up? (A `select`'s returned columns is decided at compile time, and doesn't take table data into consideration.) – jarlh Feb 24 '16 at 08:07
  • 2
    Consider handling issues of data display in application level code – Strawberry Feb 24 '16 at 08:19
  • I guess this post might help you - http://stackoverflow.com/questions/1241178/mysql-rows-to-columns – Sanchita Feb 24 '16 at 11:17

0 Answers0