0
我有代碼爲主客場結果在單獨的查詢,但我不確定如何加入這一起來獲取主客場。加入主客場比賽的結果在體育表
碼網站首頁體育聯賽
SELECT
teamName 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
teamHomeID Team,
1 P,
IF(matchScoreHome > matchScoreAway,1,0) W,
IF(matchScoreHome = matchScoreAway,1,0) D,
IF(matchScoreHome < matchScoreAway,1,0) L,
matchScoreHome F,
matchScoreAway A,
matchScoreHome-matchScoreAway GD,
CASE WHEN matchScoreHome > matchScoreAway THEN 3 WHEN matchScoreHome = matchScoreAway THEN 1 ELSE 0 END PTS
FROM tblmatches WHERE matchstatus = 'FT' AND competitionID = 1 AND seasonID = 2
) as tot
JOIN tblteam t ON tot.team=t.teamID
GROUP BY Team
ORDER BY SUM(Pts) DESC ;
CODE AWAY體育聯賽
SELECT
teamName 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
teamAwayID Team,
1 P,
IF(matchScoreHome < matchScoreAway,1,0) W,
IF(matchScoreHome= matchScoreAway,1,0) D,
IF(matchScoreHome > matchScoreAway,1,0) L,
matchScoreAway F,
matchScoreHome A,
matchScoreAway-matchScoreHome GD,
CASE WHEN matchScoreHome < matchScoreAway THEN 3 WHEN matchScoreHome = matchScoreAway THEN 1 ELSE 0 END PTS
FROM tblmatches WHERE matchstatus = 'FT' AND competitionID = 1 AND seasonID = 2
) as tot
JOIN tblteam t ON tot.team=t.teamID
GROUP BY Team
ORDER BY SUM(Pts) DESC ;
每個表將類似於遵循
--------------------------------------------------
¦ Team Name ¦ P ¦ W ¦ D ¦ L ¦ F ¦ A ¦ GD ¦ Pts ¦
¦ Man City ¦ 8 ¦ 6 ¦ 0 ¦ 2 ¦ 23 ¦ 10 ¦ 13 ¦ 18 ¦
¦ Tottehham ¦ 8 ¦ 4 ¦ 4 ¦ 0 ¦ 14 ¦ 5 ¦ 9 ¦ 16 ¦
--------------------------------------------------
我想這兩個表聯合起來得到的東西如下所示:
-----------------------------------------------------------------------------
Team Name ¦ P ¦ W ¦ D ¦ L ¦ F ¦ A ¦ GD ¦ HW ¦ HD ¦ HL ¦ HF ¦ HA ¦ AW ¦ AD ¦ AL ¦ PTS ¦
謝謝,我不知道如何合併therysys,我很新的SQL,所以嘗試但沒有得到遠 –