I have the following tables for a competition:
User:
- Id
- Name
- EntryId
Entry:
- Id
- Age
- Gender
- State
GameResult:
- Id
- EntryId
- Duration
- Score
QuestionResult:
- Id
- EntryId
- Correct
- UsersAnswer
Each entry will have multiple games, and multiple questions. I need to perform a query that will find a list of the highest scores, and then also break down highest score by demographic, i.e. Age, Gender, State.
The calculations are as follows:
Each correct question will have a score value assigned, e.g. 10 points for each correct answer. Each game will have the score already defined in its column.
So, for an entry, the total score will be:
(Count(Qn.Correct) * QuestionScore) + SUM(G1.Score, G2.Score, Gn.Score)
Not sure where to start in figuring this query out.
note sure individual answer score would be relevant here since you already have final score on the GameResult table.
then repeat the same thing for the gender and state.
edit: ok, I am not sure I am following your high level design here, but whatever…
You need to group your results by the entry ID first, and then by Age/Gender/State. An extra complexity level, but otherwise exactly the same task.