我有一张表格,里面装满了学生的考勤数据,我们正在迁移到另一个学生信息系统,他们希望平面文件的格式是每个学生每天一行所有7个时期列出。现在,我们的数据每个时期每天存储一条记录(请参阅附加模式)对这些数据进行格式设置以符合我上面列出的内容的最佳方式是什么?我还附上他们想要的截图(每一行都是一列)。将一列中的数据分成多列
新增数据的截屏。
我有一张表格,里面装满了学生的考勤数据,我们正在迁移到另一个学生信息系统,他们希望平面文件的格式是每个学生每天一行所有7个时期列出。现在,我们的数据每个时期每天存储一条记录(请参阅附加模式)对这些数据进行格式设置以符合我上面列出的内容的最佳方式是什么?我还附上他们想要的截图(每一行都是一列)。将一列中的数据分成多列
新增数据的截屏。
好了,所以支点是我需要的不是什么。我最终与一位收藏家谈论了我的问题,他告诉我使用子查询。所以这就是我解决它的方法!
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
我完全被你的问题搞糊涂了。你说他们希望列出所有的“7个时期”。我在你的模式中看不到时期......我看到了absent_period。我也看到有超过7个Abs代码期。我可以看到Abs代码周期1到Abs代码周期14.如果您使用真实数据而不仅仅是模式和布局,这将非常有帮助。 –
我添加了数据的屏幕截图。有7个以上的时间适应其他学校,我们只有7个抱歉的混乱。 – Mysteri0n
什么版本的SQL? –