SQLServerデータベースに次のテーブルがあります。
(1) StudentMaster (StudentId, StudentName)
(2) SubjectMaster (SubjectId, SubjectName)
(3) AttendanceMaster (AttendanceId,StudentId,SubjectId,Attendance,Date)
Data in AttendanceMaster can be in Following format :
AttendanceMaster :
AttendanceId StudentId SubjectId Attendance Date
3001 33 1 P 1/1/2011
3001 57 2 P1 1/2/2011
3001 33 1 P 1/3/2011
3001 57 2 P2 1/4/2011
3001 33 1 P1 1/5/2011
次の形式でSubjectWiseの個別出席の詳細を取得したい:
StudentName SubjectName Total(P) Total(P1) Total(P2)
Ghanshyam Maths 90 10 5
John Maths 85 15 5
Ghanshyam Science 70 20 15
John Science 80 30 5
私は次のクエリを試しました:
select StudentName, SubjectName,
(select count(*) from AttendanceMaster innerAM where innerAM.StudentId = StdM.StudentId and innerAM.SubjectId=SubM.SubjectId and innerAM.Attendance = 'P') as Total(P),
(select count(*) from AttendanceMaster innerAM where innerAM.StudentId = StdM.StudentId and innerAM.SubjectId=SubM.SubjectId and innerAM.Attendance = 'P1') as Total(P1),
(select count(*) from AttendanceMaster innerAM where innerAM.StudentId = StdM.StudentId and innerAM.SubjectId=SubM.SubjectId and innerAM.Attendance = 'P1') as Total(P2)
from AttendanceMaster AM inner join StudentMaster StdM on AM.StudentId = StdM.StudentId
inner join SubjectMaster SubM on AM.SubjectId = SubM.SubjectId
結果は出ましたが、実行に時間がかかりすぎます。(約5〜6分)
so what can i do to decrease execution time...
また、Total(P)、Toal(P1)、Total(P2)を取得するクエリを作成するのは正しい方法ですか?他のSQL構文を指定してください
ありがとう