SELECT
max( CASE dw WHEN 2 THEN dm END ) AS Mo,
max( CASE dw WHEN 3 THEN dm END ) AS Tu,
max( CASE dw WHEN 4 THEN dm END ) AS We,
max( CASE dw WHEN 5 THEN dm END ) AS Th,
max( CASE dw WHEN 6 THEN dm END ) AS Fr,
max( CASE dw WHEN 7 THEN dm END ) AS Sa,
max( CASE dw WHEN 1 THEN dm END ) AS Su
FROM
(
SELECT
DATE_FORMAT( dy, '%u' ) wk,
DATE_FORMAT( dy, '%d' ) dm,
DATE_FORMAT( dy, '%w' ) + 1 dw
FROM
(
SELECT
DATE_ADD( dy, INTERVAL t500.id - 1 DAY ) dy,
x.mth
FROM
(
SELECT
DATE_ADD(
CURRENT_DATE,
INTERVAL - DAYOFMONTH( CURRENT_DATE ) + 1 DAY
) dy,
DATE_FORMAT( CURRENT_DATE, '%m' ) mth
FROM
DUAL
) x,
t500
WHERE
t500.id <= 31
AND DATE_FORMAT(
DATE_ADD( dy, INTERVAL t500.id - 1 DAY ),
'%m'
) = mth
) y
) z
GROUP BY
wk
ORDER BY
wk