convert rows to columns in mysql -


i have table in database looks like:

enter image description here

i trying create query gives me result like:

enter image description here

and when searching trough forum did found information converting rows columns using aggregate function and/or using predefined statement. example did found did try following queries doesn't work don't understand how work copy query. did try use data in it:

select fk_playerid name, roundid roundno, score from( roundid, case when roundid = 1 score end 1, case when roundid = 2 score end 2, case when roundid = 3 score end 3, cup ) cup group fk_playerid 

and second one:

select fk_playerid name, roundid roundno, score max(case when'roundid' = 1, score end) roundno1, max(case when'roundid' = 2, score end) roundno2, max(case when'roundid' = 3, score end) roundno3 cup order fk_playerid 

and question how query must , need little explanation how works.

the second 1 pretty close:

select c.fk_playerid,        p.name        max(case when c.roundid = 1 c.score end) roundno1,        max(case when c.roundid = 2 c.score end) roundno2,        max(case when c.roundid = 3 c.score end) roundno3 cup c join player p on c.fk_playerid = p.id group c.fk_playerid, p.name 

you grouping fk_playerid. lets consider player = 1. this

case when roundid = 1 score end  

will produce following set score: {1, null, null}. max return 1.

case when roundid = 2 score end  

will produce following set score: {null, 1, null}. max return 1.

case when roundid = 3 score end  

will produce following set score: {null, null, 1}. max return 1.

the same player = 19.


Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -

How to provide Authorization & Authentication using Asp.net, C#? -