我对体育排名页面有这样的查询...
SELECT
name AS Team,
SUM(P) AS P,
SUM(W) AS W,
SUM(D) AS D,
SUM(L) AS L,
SUM(F) as F,
SUM(A) AS A,
SUM(GD) AS GD,
SUM(Pts) AS Pts
FROM (
SELECT *,
team1Id Team,
1 P,
IF(team1Sets > team2Sets,1,0) W,
IF(team1Sets = team2Sets,1,0) D,
IF(team1Sets < team2Sets,1,0) L,
team1Games F,
team2Games A,
team1Games-team2Games GD,
CASE WHEN team1Sets > team2Sets THEN 3
WHEN team1Sets = team2Sets THEN 1
ELSE 0
END PTS
FROM ligas_match
WHERE groupId = 1
UNION ALL
SELECT *,
team2Id Team,
1,
IF(team1Sets < team2Sets,1,0),
IF(team1Sets = team2Sets,1,0),
IF(team1Sets > team2Sets,1,0),
team2Games,
team1Games,
team2Games-team1Games,
CASE WHEN team1Sets < team2Sets THEN 3
WHEN team1Sets = team2Sets THEN 1
ELSE 0
END PTS
FROM ligas_match
WHERE groupId = 1
) AS tot
JOIN ligas_team t ON tot.Team=t.id
GROUP BY Team
ORDER BY
SUM(Pts) desc,
SUM(GD) desc
这种结构非常适合那些没有足球等部分成绩的体育联盟。但我正努力让它成为一个乒乓球联赛。
在padel联赛中,比赛包含n组,赢得更多组的球队赢得比赛和3分,如果两支球队赢得相同数量的比赛,则比赛被视为平局,他们每人获得1分。这些集合也分为游戏,在一组中赢得更多游戏获得集合(无法绘制)。现在我在匹配表中存储集数据(team1Sets,team2Sets,team1Games,team2Games),查询工作正常。
然而,由于在匹配表和集合表中存储集合数据是多余的,我需要将集合数据存储在另一个名为ligas_set的表中,并以某种方式在两个表之间进行连接(ligas_match和ligas_match上的ligas_set) .id = ligas_set.matchId)。
这是小提琴http://sqlfiddle.com/#!2/483c7
所需的结果集是联盟/组中每个队伍的排名表,他们的比赛是P;他们的胜利,W;他们的抽奖,D;他们的失败,L;他们的每场比赛赢了,F;他们的每场比赛都是Lost,A; GD赢得和输掉比赛之间的区别;和他们的总分,Pts。
有人可以帮助解决此问题吗?