SELECT
id,
vorname,
nachname,
@d1 AS datum1,
MAX(IF(datum = @d1, FS, NULL)) AS FS1,
MAX(IF(datum = @d1, SS, NULL)) AS SS1,
MAX(IF(datum = @d1, NS, NULL)) AS NS1,
@d2 AS datum2,
MAX(IF(datum = @d2, FS, NULL)) AS FS2,
MAX(IF(datum = @d2, SS, NULL)) AS SS2,
MAX(IF(datum = @d2, NS, NULL)) AS NS2,
@d3 AS datum3,
MAX(IF(datum = @d3, FS, NULL)) AS FS3,
MAX(IF(datum = @d3, SS, NULL)) AS SS3,
MAX(IF(datum = @d3, NS, NULL)) AS NS3,
@d4 AS datum4,
MAX(IF(datum = @d4, FS, NULL)) AS FS4,
MAX(IF(datum = @d4, SS, NULL)) AS SS4,
MAX(IF(datum = @d4, NS, NULL)) AS NS4,
@d5 AS datum5,
MAX(IF(datum = @d5, FS, NULL)) AS FS5,
MAX(IF(datum = @d5, SS, NULL)) AS SS5,
MAX(IF(datum = @d5, NS, NULL)) AS NS5,
@d6 AS datum6,
MAX(IF(datum = @d6, FS, NULL)) AS FS6,
MAX(IF(datum = @d6, SS, NULL)) AS SS6,
MAX(IF(datum = @d6, NS, NULL)) AS NS6,
@d7 AS datum7,
MAX(IF(datum = @d7, FS, NULL)) AS FS7,
MAX(IF(datum = @d7, SS, NULL)) AS SS7,
MAX(IF(datum = @d7, NS, NULL)) AS NS7,
@d7 AS datum8,
MAX(IF(datum = @d8, FS, NULL)) AS FS8,
MAX(IF(datum = @d8, SS, NULL)) AS SS8,
MAX(IF(datum = @d8, NS, NULL)) AS NS8
FROM
( SELECT
@d1 := '2010-12-16',
@d2 := DATE_ADD(@d1, INTERVAL 1 DAY),
@d3 := DATE_ADD(@d1, INTERVAL 2 DAY),
@d4 := DATE_ADD(@d1, INTERVAL 3 DAY),
@d5 := DATE_ADD(@d1, INTERVAL 4 DAY),
@d6 := DATE_ADD(@d1, INTERVAL 5 DAY),
@d7 := DATE_ADD(@d1, INTERVAL 6 DAY),
@d8 := DATE_ADD(@d1, INTERVAL 7 DAY)
) AS vars,
(
SELECT
id,
vorname,
nachname,
datum,
schicht,
if( (schicht like '%1.%' or schicht='egal'),'X','') as FS ,
if( (schicht like '%2.%' or schicht='egal'),'X','') as SS,
if( (schicht like '%3.%' or schicht='egal'),'X','') as NS
FROM
eingabe
WHERE
datum BETWEEN @d1 AND @d8
) AS d
GROUP BY nachname