I'm trying to develop a ranking table for a sort of questionnaire.
Each day a question is asked at 4:00 p.m., which can be answered by 17:59:59 the next day. The table has to show the position of the participants taking into account the number of correct answers and the time.
In other words, it responds right and faster it comes first. The number of questions answered also counts, if arch does not respond one day is penalized.
My table will be of the sort:
+-------+---------+---------------------+
|userid | acertou | timestamp |
+-------+---------+---------------------+
| 2 | 1 | 2018-02-07 16:00:01 |
| 1 | 1 | 2018-02-07 16:02:00 |
| 3 | 1 | 2018-02-07 17:00:00 |
| 1 | 0 | 2018-02-08 16:00:02 |
| 3 | 1 | 2018-02-08 16:00:05 |
| 2 | 0 | 2018-02-08 16:01:00 |
+-------+---------+---------------------+
I've already started with this query:
SELECT 'userid', 'acertou', 'timestamp',
count(acertou) as cont
FROM 'resultados'
WHERE acertou = 1
GROUP BY 'userid '
ORDER BY cont DESC, timestamp DESC
But I realized that this is not what I want because the ranking has to be cumulative but taking into account the several days.
Does anyone have an idea how I can do this?