簡體   English   中英

MySQL 數據透視表 - 行到列

[英]MySQL pivot tables - rows to colums

此查詢

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

給我這個結果

圖1

我怎樣才能得到與此類似的結果

圖2

通過這個答案解決

選擇學生。學生 ID,學生。 Name ,

IF ( ( SELECT DISTINCT 1 FROM 考勤 WHERE考勤.StudentID = student.StudentID AND date = '2015-09-07' ) = 1, 'Present', 'Absent' ) AS 2015-09-07 ,

IF ( ( 從出勤率中選擇 DISTINCT 1 WHERE 出勤.StudentID = student.StudentID AND date = '2015-09-14' ) = 1, 'Present', 'Absent' ) AS 2015-09-14 ,

student.WorkshopID 來自學生

來自@Hitesh Mundra

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM