Se stai usando MySQL 8+, possiamo gestirlo usando ROW_NUMBER
:
WITH cte AS (
SELECT *, ROW_NUMBER() OVER (PARTITION BY Date ORDER BY Time) rn
FROM attendancedata
WHERE EnrolledID = 23
)
SELECT
Date,
MAX(CASE WHEN rn = 1 THEN Time END) AS PO1,
MAX(CASE WHEN rn = 2 THEN Time END) AS PO2,
MAX(CASE WHEN rn = 3 THEN Time END) AS PO3,
MAX(CASE WHEN rn = 4 THEN Time END) AS PO4,
MAX(CASE WHEN rn = 5 THEN Time END) AS PO5,
MAX(CASE WHEN rn = 6 THEN Time END) AS PO6,
MAX(CASE WHEN rn = 7 THEN Time END) AS PO7
FROM cte
GROUP BY
Date
ORDER BY
Date;
Ma nota che in generale è desiderabile memorizzare data e ora in un unico datetime
campo con MySQL. In questo caso particolare, ha funzionato bene, ma potrebbe non essere sempre vero.