Here’s a stored procedure which generates PIVOT (or crosstab) queries in MySQL, sort of like what you used to be able to do in Microsoft Access, before everything