Gabe
Gabe

Reputation: 1286

Database table for grades

I'm trying to define a table to store student grades for a online report card. I can't decide how to do it, though.

The grades are given by subject, in a trimestral period. Every trimester has a average grade, the total missed classes and a "recovering grade" (I don't know the right term in English, but it's an extra test you take to try to raise your grade if you're below the average), I also gotta store the year average and final "recovering grade". Basically, it's like this:

      |1st Trimester      |2nd Trimester      |3rd Trimester
Subj. |Avg.  |Mis.  |Rec  |Avg.  |Mis.  |Rec  |Avg.  |Mis.  |Rec  |Year Avg.  |Final Rec.
Math  |5.33  |1     |4    |8.0   |0           |7.0   |2           |6.5        |7.0
Sci.  |5.33  |1     |4    |8.0   |0           |7.0   |2           |6.5        |7.0

I could store this information in a single DB row, with each row like this:

1tAverage | 1tMissedClasses | 1tRecoveringGrade | 2tAverage | 2tMissedClasses | 2tRecoveringGrade

And so on, but I figured this would be a pain to mantain, if the scholl ever decides to grade by bimester or some other period (like it used to be up until 3 years ago).
I could also generalize the table fields, and use a tinyint for flagging for which trimester those grades are, or if they're the year finals. But this one would ask for a lot of subqueries to write the report card, also a pain to mantain.

Which of the two is better, or is there some other way? Thanks

Upvotes: 1

Views: 5308

Answers (4)

Handruin
Handruin

Reputation: 88

You could try structuring it like this with your tables. I didn't have all the information so I made some guesses at what you might need or do with it all.

TimePeriods:

  • ID(INT)
  • PeriodTimeStart(DateTime)
  • PeriodTimeEnd(DateTime)
  • Name(VARCHAR(50)

Students:

  • ID(INT)
  • FirstName(VARCHAR(60))
  • LastName(VARCHAR(60))
  • Birthday(DateTime)
  • [any other relevant student field information added...like contact info, etc]

Grading:

  • ID(INT)
  • StudentID(INT)
  • GradeValue(float)
  • TimePeriodID(INT)
  • IsRecoveringGrade(boolean)

MissedClasses:

  • ID(INT)
  • StudentID(INT)
  • ClassID(INT)
  • TimePeriodID(INT)
  • DateMissed(DateTime)

Classes:

  • ID(INT)
  • ClassName (VARCHAR(50))
  • ClassDescription (TEXT)

Upvotes: 5

Ali Afshar
Ali Afshar

Reputation: 41633

This comes to mind.

(But seriously, err on the side of too many tables, not too few. Handruin has the best solution I see so far).

Upvotes: 0

Turnkey
Turnkey

Reputation: 9406

It's better to have a second table representing trimester, and have a foreign key reference to the trimester from the grades table (and store individual grades in the grades table). Then do the averages, missed classes, etc using SQL functions SUM and AVG.

Upvotes: 0

davr
davr

Reputation: 19137

I think the best solution is to store one row per period. So you'd have a table like:

grades
------
studentID
periodNumber
averageGrade
missedClasses
recoveringGrade

So if it's 2 semesters, you'd have periods 1 and 2. I'd suggest using period 0 to mean "overall for the year".

Upvotes: 0

Related Questions