出席、期間、ステータスの3つのテーブルがあります。私の出力を得るために、私は...誰が助けることができる各学生のすべての期間の出席を取得
SELECT * FROM status s
LEFT JOIN (
SELECT period_id,p_name,student_id,date,status
FROM period p
LEFT JOIN attendance a
ON p.period_id=a.period_id)t1
ON s.status=t1.status
は、しかし、それは所望の出力を与えていないこのクエリを書いた
出席:
---------------------------------------------------------
id | student_id | period_id |date | Status |
--------------------------------------------------------
1 | 1 | 1 |2016-12-24 | Present
--------------------------------------------------------|
2 | 1 | 3 |2016-12-24 | Absent
--------------------------------------------------------|
3 | 2 | 1 |2016-12-24 | Late
--------------------------------------------------------|
4 | 2 | 2 |2016-12-24 | Present
期間:
-----------------------
period_id | p_name |
-----------------------
1 | period1 |
-----------------------
2 | period2 |
-----------------------
3 | period3 |
ステータス:
で出力
-----------------------------------------------------
student_id | period_id | date | Status |
-----------------------------------------------------
1 | 1 | 2016-12-24 | Present |
-----------------------------------------------------
1 | 2 | 2016-12-24 | null |
-----------------------------------------------------
1 | 3 | 2016-12-24 | Absent |
-----------------------------------------------------
2 | 1 | 2016-12-24 | Late |
-----------------------------------------------------
2 | 2 | 2016-12-24 | Present |
-----------------------------------------------------
2 | 3 | 2016-12-24 | null
あなたが望むものを得るには、LEFT JOINを使用する必要があります。 – Barmar