I wonder if anyone can help with this problem.
I have two tables, edhistory and cal_term. The edhistory records the start and end dates of a pupil’s time at a particular school. The relevant fields are:
SchoolID
PupilID
StartDate
EndDate
The cal_term table contains details about the school calendar, broken down into terms (we mainly use terms rather than semesters in the UK).
Relevant fields are:
TermStartDate
TermEndDate
TermName
SchoolYear
Sample data from edhistory:
SCHOOLID PUPILID STARTDATE ENDDATE
2035200 22686 09/01/2001 06/09/2004
2032024 22686 07/09/2004 27/07/2006
2034271 22686 05/09/2006
Sample data from cal_term:
AC_YEAR TERM_NAME TERM_START_DATE TERM_END_DATE
06/07 Autumn 04/09/2006 15/12/2006
06/07 Spring 03/01/2007 30/03/2007
06/07 Summer 16/04/2007 25/07/2007
07/08 Autumn 03/09/2007 21/12/2007
07/08 Spring 07/01/2007 04/04/2008
07/08 Summer 21/04/2008 23/07/2008
What I want to achieve is a query that will show for each term what school the pupil was registered at. So, for this example, the pupil with PupilID 22686, it would show:
06/07 Autumn 2034271
06/07 Spring 2034271
06/07 Summer 2034271
07/08 Autumn 2034271
Since the date is now 23/11/07, and this falls within the Autumn term of the 07/08 year, and the pupil has no EndDate for the school 2034271, this would be the last record.
Since there are no rows in the cal_term table for earlier than September 2006, no rows would be returned for the edhistory records up to July 2006.
Is this possible, and if so, what would be the best SQL?
(For information, the actual implementation needs to be in Oracle (9i), but I don’t know of any specific functions in Oracle that would help).
Thanks in advance for any help.
I have two tables, edhistory and cal_term. The edhistory records the start and end dates of a pupil’s time at a particular school. The relevant fields are:
SchoolID
PupilID
StartDate
EndDate
The cal_term table contains details about the school calendar, broken down into terms (we mainly use terms rather than semesters in the UK).
Relevant fields are:
TermStartDate
TermEndDate
TermName
SchoolYear
Sample data from edhistory:
SCHOOLID PUPILID STARTDATE ENDDATE
2035200 22686 09/01/2001 06/09/2004
2032024 22686 07/09/2004 27/07/2006
2034271 22686 05/09/2006
Sample data from cal_term:
AC_YEAR TERM_NAME TERM_START_DATE TERM_END_DATE
06/07 Autumn 04/09/2006 15/12/2006
06/07 Spring 03/01/2007 30/03/2007
06/07 Summer 16/04/2007 25/07/2007
07/08 Autumn 03/09/2007 21/12/2007
07/08 Spring 07/01/2007 04/04/2008
07/08 Summer 21/04/2008 23/07/2008
What I want to achieve is a query that will show for each term what school the pupil was registered at. So, for this example, the pupil with PupilID 22686, it would show:
06/07 Autumn 2034271
06/07 Spring 2034271
06/07 Summer 2034271
07/08 Autumn 2034271
Since the date is now 23/11/07, and this falls within the Autumn term of the 07/08 year, and the pupil has no EndDate for the school 2034271, this would be the last record.
Since there are no rows in the cal_term table for earlier than September 2006, no rows would be returned for the edhistory records up to July 2006.
Is this possible, and if so, what would be the best SQL?
(For information, the actual implementation needs to be in Oracle (9i), but I don’t know of any specific functions in Oracle that would help).
Thanks in advance for any help.