I have a table as shown above which is from the following query:
SELECT f_id, f_datetime, (f_player1_score+f_player2_score) AS legs,
SUM(f_player1_score+f_player2_score) OVER (ORDER BY f_datetime DESC) AS total_legs,
IF(DATE(f_datetime) = DATE(NOW()), 1, 0) AS f_status
FROM results
I want the f_status query column I've created to have the following rules:
1 - If `DATE(f_datetime) = DATE(NOW())` THEN assign `f_status=1`, which is what I've done.
2 - take the maximum total legs where `f_status=1` (i.e. 4 and add 50), then assign `f_status=2` up to total_legs=54,
3) Anything after 2) assign as 3
Desired output below:
I know how to do this but it requires many table aliases and is really messy. Is there a simple way to go about it?
Thanks