/ Published in: MySQL
You have a schedule table (period, day, subject, room) with a primary key period,day to avoid duplicate bookings. You wish to display the schedule as periods, subjects and rooms in rows, and days of the week in columns.
Expand |
Embed | Plain Text
SELECT period, MAX(IF(DAY=1, CONCAT(subject,' ',room), '')) AS Mon, MAX(IF(DAY=2, CONCAT(subject,' ',room), '')) AS Tue, MAX(IF(DAY=3, CONCAT(subject,' ',room), '')) AS Wed, MAX(IF(DAY=4, CONCAT(subject,' ',room), '')) AS Thu, MAX(IF(DAY=5, CONCAT(subject,' ',room), '')) AS Fri FROM schedule GROUP BY period
You need to login to post a comment.
