I've got a new requirement for my ancient Xataface system.
The system is used to enter scores for a few variations on one sporting match.
In the past the maximum score per person was based on the particular match (i.e. there might be 4 members of a team and the maximum score for any member was the same, so it was a property of the matches table).
Now we are changing it so that all 4 positions on the team can have a different maximum.
I've added a new table like: MaxScores: MatchId, Position, MaxScore
So for matchid=1, position=1, max=100. matchid=1, position=2, max=80 etc.
I want to use the MaxScore from MaxScores if there is one else defer back to the original in the Matches table. In SQL I can use a clause in the select like:
CASE WHEN EXISTS (SELECT MaxScore FROM MaxScores ms WHERE ms.MatchId = matches.MatchId and ms.Position = scores.Position) THEN MaxScores.MaxScore ELSE matches.maxScore
I tried to graft this into the SQL for the scores table but I got an error on the case
Fatal error: Failed parsing SQL query on select: <query> found: "CASE" in C:\wamp64\www\postals\xataface-2.2.5\lib\SQL\Parser.php on line 1829
The SQL works as expected normally but clearly Xataface can't parse it,.
Can anyone suggest how I can pick the right Max?
Plan B which I want to avoid is populating the MaxScores table with every position of every match and making it the one and only source of the MaxScore. That is a lot of redundant data since only 3 out of 20 events use the new way :-(
Hope I've explained it clearly enough to get a suggestion...