pivot - Create a mysql temporary table with a variable number of columns -


i'm trying display results of game in table. raw data looks following:

matchid  stageid  stringid  shooterid   finalscore 118         1       3       10040       18.008 118         1       2       10040       13.639 118         1       1       10040       9.895 118         1       3       10051       15.464 118         1       2       10051       23.842 118         1       1       10051       21.018 118         1       3       10041       13.601 118         1       2       10041       8.151 118         2       1       10041       49.5 118         2       2       10041       59.5 118         2       3       10041       49.5 118         2       1       10040       69.5 118         2       3       10040       39.5 118         2       1       10051       109.5 118         2       2       10051       89.5 118         2       3       10051       99.5 118         2       2       10040       59.5 ... many more rows variable number of stageid's 

the output table should following:

shooterid   stage1  stage2  total 10039       38.26   188.50  226.76 10040       41.54   168.50  210.04 10041       28.33   158.50  186.83 10042       59.98   355.50  415.48 10043       49.23   198.50  247.73 10047       33.16   218.50  251.66 10048       33.21   358.50  391.71 10051       60.32   298.50  358.82 10052       30.74   278.50  309.24 10053       62.49   268.50  330.99 

i've tried doing group_concat(), things got nasty when tried add total column.

now i've decided try , stored proceedure using temporary tables. problem can't figure out how create temporary table variable number of columns. did find similar question, using mssql , did not work mysql. (procedure create table variable number of columns)

i did find examples of doing static number of columns, creating temporary table dynamically has me stumped. can point me in right direction?


Comments