我有一个名为出席的表,有 2 个属性(id、备注)。我想从考勤表中显示每个 id 的缺勤或迟到记录。
Attendance Table
|ID | Remarks |
=============================
|1 | Absent |
|1 | Late |
|2 | Absent |
|2 | Absent |
|3 | Late |
Sample Output
|ID | Absent | Late |
==================================
|1 | 1 | 1 |
|2 | 2 | |
|3 | | 1 |
目前,我只能使用以下代码输出 2 列,(ID 和 Absent)或(ID 和 Late):
SELECT id, count(remarks) AS Absent
FROM attendance
WHERE remarks = 'Absent'
GROUP BY id;
我不能同时显示缺席和迟到的列..请帮忙。谢谢。