credo che la lettura di questo pdf ti possa aiutare....
http://datacharmer.org/downloads/pivot_tables_mysql_5.pdf