0

学生の出席データでいっぱいのテーブルがあります。別の学生情報システムに移行しています。フラットファイルを希望する方法は、7つの期間すべてがリストされた毎日の学生ごとに1行です。現在、データは期間ごとに1日1レコードとして保存されています(添付のスキーマを参照)。このデータを上記のリストに一致するようにフォーマットするための最良の方法は何でしょうか。また、彼らが望む方法のスクリーンショットを添付しています(各行は列です)。

データのスクリーンショットを追加しました。

現在のデータベーススキーマ

それが何である必要があるか

ここに画像の説明を入力してください

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 に答える