Created
April 22, 2013 20:12
-
-
Save chrishaid/5438105 to your computer and use it in GitHub Desktop.
This SQL query pulls daily student attendance for each student enrolled on each day for the date range given.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT | |
m.schoolid, | |
m.grade_level, | |
m.calendardate, | |
m.STUDENT_NUMBER AS StudentID, | |
m.lastfirst, | |
m.Enrolled, | |
a.Att_Code, | |
a.Description as AttDescr, | |
a.Presence_Status_CD, | |
a.COURSE_CREDIT_POINTS, | |
CASE | |
WHEN a.Presence_Status_CD = 'Absent' THEN a.COURSE_CREDIT_POINTS | |
ELSE 0 | |
END as Absent | |
FROM ( | |
SELECT | |
psmd.SchoolID, | |
psmd.grade_level, | |
psmd.calendardate, | |
psmd.studentid, | |
s.STUDENT_NUMBER, | |
s.LASTFIRST, | |
1 as Enrolled | |
FROM PS_Membership_Defaults psmd | |
LEFT JOIN students s ON psmd.StudentID = s.id | |
Where calendardate >= TO_DATE('",date.first,"','yyyy-mm-dd') | |
AND calendardate <= TO_DATE('",date.second,"','yyyy-mm-dd') | |
) m | |
LEFT JOIN ( | |
SELECT | |
att.schoolid, | |
att.StudentID, | |
att.Att_Date, | |
attc.Att_Code, | |
attc.Description, | |
attc.Presence_Status_CD, | |
attc.COURSE_CREDIT_POINTS | |
FROM Attendance att | |
INNER JOIN Attendance_Code attc ON att.Attendance_CodeID = attc.ID | |
WHERE | |
att.Att_Mode_Code = 'ATT_ModeDaily' | |
AND att.Att_Date >= TO_DATE('",date.first,"','yyyy-mm-dd') | |
AND att.Att_Date <= TO_DATE('",date.second,"','yyyy-mm-dd') | |
AND (attc.att_code = 'A' OR attc.att_code = 'S' or attc.att_code = 'X' or attc.att_code = 'H') | |
) a | |
ON m.STUDENTID = a.studentid AND m.calendardate =a.Att_Date AND m.schoolID = a.schoolid | |
ORDER BY schoolid, grade_level, calendardate; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment