I actually struggled to come up with a decent title for my question.
I have a table that keeps a log of when users get to a level of a particular game. Levels go from 1 to 5 but I'm particularly interested in knowing how long they got stuck in level 3 (for any game).
My table (gamehistorylog):
gameid (int)
level (int)
dateofchange (date)
I'm obviously not interested in games where the level is less than 3.
I can use datediff() but I'm not sure how to form the query to get the combined data of students that are at level 3 still (how long have they been there?) and those that passed it already at levels 4 & 5 (how long did the spend in level 3)?
Every time a level is passed, a table record is generated with the new level and the date for the specific game.
Expected output is just a list of all games on the table that are at or above level 3 and time spent on level 3.
I have another table that keeps the official game status so i can join with that table and query the date of the most recent date for games where status = 3.
select l.gameid as gid,
DATEDIFF(NOW(), max(dateofchange)) as datediff
from gamehistorylog l
join games g on g.gameid = l.gameid
where g.status = 3 and l.level = 3 ;
This will get me the data for all instances where the highest level is 3. I don't know how to get it for those that already progressed to higher levels and then combine it all.