First of all, you have to
unpivot[
^] data {
p1, p2, p3, p4
} to
PD
and
PDValue
fields then pivot them again - on
Day
field.
SELECT PD, [mon], [tue], [wed], ...
FROM (
SELECT id, Day, PD, PDValue
FROM (
SELECT id, Day, p1, p2, p3, p4
FROM TIMETABLE
) pvtData
UNPIVOT (PDValue FOR PD IN (p1, p2, p3, p4))
) AS unpvtData
PIVOT (PDValue FOR Day IN ([mon], [tue], [wed], ...)) AS Final
Note: not tested!