0

我有一个完整的学生出勤数据表,我们正在迁移到另一个学生信息系统,他们希望平面文件的方式是每个学生每天一行,列出所有 7 个时段。现在,我们的数据存储为每个期间每天一条记录(请参阅附件架构)格式化此数据以匹配我上面列出的内容的最佳方法是什么。我还附上了他们想要的屏幕截图(每一行都是一列)。

添加了数据的屏幕截图。

我们当前的数据库模式

它需要是什么

在此处输入图像描述

4

2 回答 2

1

看看 PIVOT 和 UNPIVOT。

是一个例子

于 2012-05-18T15:36:30.453 回答
0

好的,所以枢轴不是我需要的。我最终与一位大学讨论了我的问题,他告诉我使用子查询。所以这就是我解决它的方法!

select distinct student_id,school_year,school_number,absent_date,
(select absent_code from attend_student_detail a2 where a2.student_id=a.student_id and a2.absent_date=a.absent_date and a2.absent_period='H') as daily_code,
(select absent_code from attend_student_detail a2 where a2.student_id=a.student_id and a2.absent_date=a.absent_date and a2.absent_period='1') as per_1,
(select absent_code from attend_student_detail a2 where a2.student_id=a.student_id and a2.absent_date=a.absent_date and a2.absent_period='2') as per_2,
(select absent_code from attend_student_detail a2 where a2.student_id=a.student_id and a2.absent_date=a.absent_date and a2.absent_period='3') as per_3,
(select absent_code from attend_student_detail a2 where a2.student_id=a.student_id and a2.absent_date=a.absent_date and a2.absent_period='4') as per_4,
(select absent_code from attend_student_detail a2 where a2.student_id=a.student_id and a2.absent_date=a.absent_date and a2.absent_period='5') as per_5,
(select absent_code from attend_student_detail a2 where a2.student_id=a.student_id and a2.absent_date=a.absent_date and a2.absent_period='6') as per_6,
(select absent_code from attend_student_detail a2 where a2.student_id=a.student_id and a2.absent_date=a.absent_date and a2.absent_period='7') as per_7 

FROM attend_student_detail a

Order By Absent_Date, Student_ID
于 2012-06-25T15:28:08.077 回答