csy3024-assignment-1/scripts/queries/query10.cyp

18 lines
401 B
Plaintext

//Display the team with the most consecutive losses
MATCH (t:Team)-[p:PLAYED_IN]->(m:Match)
WITH t, p, m
ORDER BY t, m.date ASC
WITH t, collect({match: m, result: p.result}) AS matches
WITH t, reduce(count = 0, match IN matches |
CASE
WHEN match.result = "Lost" THEN count + 1
ELSE 0
END) AS loss_streak
RETURN t.name AS most_consecutive_losses, loss_streak
ORDER BY loss_streak DESC
LIMIT 1