0
我正在創建一個體育網頁,我已經達到了我無法解決自己的問題。Mysql體育聯盟表
我的問題是,我不知道如何在每個比賽日之後分別存儲每個球隊的位置。以下是我想要實現:
爲了創建排名表我有兩個表:
俱樂部:id_clubs,名
結果:matchid,比賽日,hometeam,awayteam,homegoals, awaygoals,日期,id_league
結果表中創建我的排名表是設置這樣的:
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 *,
hometeamid Team,
1 P,
IF(homegoal > awaygoal,1,0) W,
IF(homegoal = awaygoal,1,0) D,
IF(homegoal < awaygoal,1,0) L,
homegoal F,
awaygoal A,
homegoal-awaygoal GD,
CASE WHEN homegoal > awaygoal THEN 3
WHEN hometeam = awaygoal THEN 1
ELSE 0
END PTS
FROM results
WHERE id_league = '$leagueid'
AND homegoal IS NOT NULL
AND awaygoal IS NOT NULL
UNION ALL
SELECT *,
awayteamid,
1,
IF(homegoal < awaygoal,1,0),
IF(homegoal = awaygoal,1,0),
IF(homegoal > awaygoal,1,0),
awaygoal,
homegoal,
awaygoal-homegoal GD,
CASE WHEN homegoal < awaygoal THEN 3
WHEN homegoal = awaygoal THEN 1
ELSE 0
END
FROM results
WHERE id_league = '$leagueid'
AND awaygoal IS NOT NULL
AND homegoal IS NOT NULL
) AS tot
JOIN clubs t ON tot.Team=t.id_clubs
GROUP BY Team
ORDER BY
SUM(Pts) desc,
SUM(GD) desc
希望有人可以提供一些提示或解決方案。
我的目標是在每個比賽日後獲得每個球隊的位置。這是一個球隊的例子: 曼城: 比賽日1:第1場 比賽日2:第3場 比賽日3:第3場 比賽日4:第7場 等等。我的目標是獲得1,3,3,7的位置,這樣我就可以在第一篇文章中製作一張圖片,如圖所示 – EyemansDome 2013-04-29 14:45:01