Pretty detailed answer on pivots here:
MySQL pivot table
Some more detail:
Microsoft Books Online - PIVOT / UNPIVOT
For your specific sample, it is a nice source. However your question is slightly wrong, it isn't the average it is the max - see pivot column pivot (max(incomeamount)... for IncomeDay....)
select * from DailyIncome -- Colums to pivot
pivot ( max (IncomeAmount) -- Pivot on this column
for IncomeDay in ([MON],[TUE],[WED],[THU],[FRI],[SAT],[SUN])) -- Make colum where IncomeDay is in one of these.
as MaxIncomePerDay -- Pivot table alias
where VendorId in ('SPIKE') -- Select only for this vendor
The vendorID is determined by the where clause, see the authors comments.
I would simply recommend following the tutorial yourself, create the tables and play with the queries so you can see what is going on.
Deepsikha nailed the real answer:
with the PIVOT operator you do not explicitly specify the grouping
elements,removing the need for GROUP BY in the query
, as the column only has three columns it the vendorID qualifies for grouping –