MySQL Forums
Forum List  »  Newbie

Help on SubQuery on same table
Posted by: Prabu Kumar
Date: June 18, 2012 04:25AM

hi, i have a table as below
------------------------------------------
Item | Month | Type | Count
________________________________________
Apple | Mar | Grade1 | 500
Apple | Mar | Grade2 | 450
Apple | Mar | Grade3 | 100
Apple | Apr | Grade1 | 200
Apple | Apr | Grade3 | 300
Apple | Apr | Grade4 | 500
Apple | May | Grade5 | 1000
Orange | Mar | Grade1 | 50
Orange | Mar | Grade2 | 40
Orange | Apr | Grade1 | 100
Orange | Apr | Grade4 | 250
Orange | Apr | Grade5 | 350
Orange | May | Grade4 | 550
Orange | May | Grade5 | 1000
------------------------------------------------------

i want output as
==========================================================
Item | Month | Grade 1 | Grade 2 | Grade3 | Grade 4 | Grade 5
---------------------------------------------------------------------
Apple | Mar | 500 | 450 | 100 | 0 |0
Apple | Apr | 200 | 0 | 300 | 500 |0
Apple | May | 0 | 0 | 0 | 0 |1000
Orange | Mar | 50 | 40 | 0 | 0 |0
Orange | Apr | 100 | 0 | 0 | 250 |350
Orange | May | 0 | 0 | 0 | 550 |1000
=======================================================================
there will be always 5 grades alone in the list..
i tried my best to form query with alias, left join, but not able to make it.. i'm 3 days old with mysql.. so can you please help..

Options: ReplyQuote


Subject
Written By
Posted
Help on SubQuery on same table
June 18, 2012 04:25AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.