MySQL数据透视表 - 行到列

时间:2015-04-02 19:51:48

标签: php mysql pivot-table time-and-attendance

此查询

SELECT
    Student.StudentID,
    student.`Name`,
    attendance.Date,
    CASE
WHEN attendance.StudentID IS NOT NULL THEN
    'Present'
ELSE
    'Absent'
END AS Attendance_Status
FROM
    student
LEFT JOIN attendance ON student.StudentID = attendance.StudentID

给我这个结果

  

Figure 1

如何获得与此类似的结果

  

Figure 2

1 个答案:

答案 0 :(得分:-1)

通过这个答案解决

  

选择student.StudentID,学生。Name

     

IF((选择DISTINCT 1 FROM出席地点)             出勤率.StudentID = student.StudentID AND date =' 2015-09-07'     )= 1,'现在','缺席' )AS 2015-09-07

     

IF((选择DISTINCT 1 FROM出席地点)             出勤率.StudentID = student.StudentID AND date =' 2015-09-14'     )= 1,'现在','缺席' )AS 2015-09-14

     

student.WorkshopID来自学生

@Hitesh Mundra