Since MySQL has neither the operator PIVOTnor the function implemented, CROSSTAB()an alternative is to do selective aggregation :
SELECT diasemana
, group_concat( if(numerohora=1,codmodulo,null) ) as "1"
, group_concat( if(numerohora=2,codmodulo,null) ) as "2"
, group_concat( if(numerohora=3,codmodulo,null) ) as "3"
, group_concat( if(numerohora=4,codmodulo,null) ) as "4"
, group_concat( if(numerohora=5,codmodulo,null) ) as "5"
, group_concat( if(numerohora=6,codmodulo,null) ) as "6"
FROM horarios
GROUP BY diasemana
Since MySQL has neither the operator
PIVOT
nor the function implemented,CROSSTAB()
an alternative is to do selective aggregation :