Reputation: 11108
I have a database table that stores pupils at a school and their athletic performance. So each child will have a competitive status (Youth, U15 and Open) along with their records for certain events (long jump, high jump and 100m).
I would like to pull a report for a specific child showing the timeline of the child, movement from Youth -> U15 to Open. As well as the various records (personal best's) for the duration of the pupil being at the school.
However the database table stores oly the current status of the child as well as their current personal best's.
How can we structure the database so that the history of the child is recorded?
Upvotes: 0
Views: 364
Reputation: 427
I would add two columns, START_DATE
and END_DATE
. The most recent record will have an end date of infinity "31-Dec-9999" (or whatever the max date is in mysql) . Inserting a new row does become a bit involved though:
START_DATE
is the current date, and the END_DATE
is infinity.END_DATE
to the current date, and insert a new record where the START_DATE
is the current date, and the END_DATE
is infinity.So you might have:
PUPIL, STATUS, LONG_JUMP, START_DATE, END_DATE
Mike, Open, 2 meters, 01-Jan-2012, 31-Dec-9999
Mike, U15, 2 meters, 01-Jan-2011, 01-Jan-2012
Mike was in U15 for all of 2011, and is currently in Open as of Jan 2012.
Your queries for the "current" information will look for rows where the current date is between START_DATE
and END_DATE
, and you can query the full set by a given person to see the timeline.
Upvotes: 1