MySQL dynamic pivot table -


this question has answer here:

i have simplified data following:

+---------+-----+--------+ | item  | type  | color  | +-------+-------+--------+ |   1   |     | red    | |   1   |   b   | blue   | |   2   |     | orange | |   2   |   b   | pink   | |   2   |   c   | blue   | |   3   |   b   | yellow | +---------+-----+--------+ 

the number of 'type' per item variable, therefore, need mysql pivot solution dynamic , can handle number of types. following kind of result set need return mysql query. can see, not need summary calculation.

+---------+------+--------+--------+ | item  |      |   b    |   c    | +-------+--------+--------+--------+ |   1   | red    | blue   |        |  |   2   | orange | pink   | blue   | |   3   |        | yellow |        | +-------+--------+--------+--------+ 

i suspect solution may involve use of mysql procedure?

select item, min(a), min(b), min(c) (     select item,          case when type = 'a' color end 'a',         case when type = 'b' color end 'b',         case when type = 'c' color end 'c'     color ) tbl group item 

Comments

Popular posts from this blog

html - Firefox flex bug applied to buttons? -

html - Missing border-right in select on Firefox -

python - build a suggestions list using fuzzywuzzy -