我已經student_record表
-------------------------------------------------------------------
student_id | semester | schoolyear| name | section |
-------------------------------------------------------------------
1 | 1st Semester| 2011-2012 | john | c21 |
2 | 1st Semester| 2011-2012 | eric | c21 |
3 | 1st Semester| 2011-2012 | mark | c21 |
和考勤表
-------------------------------------------------------------------
attendance_id | stud_id | week |
-------------------------------------------------------------------
1 | 1 | 02/04/2012 |
2 | 2 | 02/04/2012 |
3 | 3 | 02/04/2012 |
4 | 1 | 02/11/2012 |
5 | 2 | 02/11/2012 |
6 | 1 | 02/18/2012 |
7 | 2 | 02/18/2012 |
8 | 3 | 02/18/2012 |
我想用sql來實現這個輸出。
-------------------------------------------------------------------
student_id | name | 02/04/2012 | 02/11/2012 | 02/18/2012 |
-------------------------------------------------------------------
1 | john | present | present | present |
2 | erik | present | absent | present |
3 | mark | present | present | present |
這對我來說很模糊,任何人都可以幫忙嗎? 我試過了,但沒有奏效。
Select week,
[02/28/2012],
[02/29/2012]
From attendance
group by student_id
你** **真正需要的結果集進行調換或者你被允許這樣做,當你準備輸出(以你的編程語言)? – zerkms 2012-02-15 03:22:58
你最好在數據透視查詢中嘗試。請在那裏查看。 http://stackoverflow.com/questions/9104483/sql-query-with-return-columns-based-on-grouping/9104641#9104641 – 2012-02-15 03:28:25
你有PHP的這個標籤。我同意zerkms並會查詢信息,然後在PHP中使用演示文稿進行格式設置。 – mikeY 2012-02-15 03:32:57