a three way circle query wins and losses

Actually, your current logic for finding a 3-way cycle is correct. The only problem is that your logic is picking up a given 3-way cycle with each of the 3 players as being a starting point. That is, you are over-counting each cycle 2 times. So, you may simply divide your count by 3 to get the correct number of cycles:

SELECT COUNT(*) / 3 AS cnt
FROM record r1
INNER JOIN record r2 ON r1.win = r2.loss
INNER JOIN record r3 ON r2.win = r3.loss AND r3.win = r1.loss

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top