PHP interesse |
|
In mijn database staan vele wedstrijden. Maar ik zou per team combinatie " thuis team"-"uit team" willen bepalen wanneer de laatste gewonnen uitwedstrijd was.
op basis van onderstaande query kan ik de "winner" bepalen.
Maar kan ik in dezelfde query ook nog eens het resultaat ( g.Game_ID of g.Game_DateTime) krijgen van de laatste keer dat "UIT" de winner is geweest?
SELECT
g.Game_ID,
g.Game_Played,
g.Season_ID,
g.Game_DateTime as datum,
g.GameType_ID,
g.Home_Team_ID,
t1.TeamName AS hometeam,
t1.Team_Shirt,
g.Away_Team_ID,
t2.TeamName AS awayteam,
t2.Team_Shirt,
g.Home_Score_FT,
g.Away_Score_FT,
CASE
WHEN (g.Home_Score_FT>g.Away_Score_FT) THEN 'thuis'
WHEN (g.Home_Score_FT=g.Away_Score_FT) THEN 'gelijk'
WHEN (g.Home_Score_FT<g.Away_Score_FT) THEN 'uit'
end as winner
FROM
af_games g,
af_teams t1,
af_teams t2
WHERE g.Home_Team_ID =31
AND g.Game_Played = 'Y'
AND g.Home_Team_ID= t1.Team_ID
AND g.Away_Team_ID= t2.Team_ID
Order by datum ASC;
SELECT g.Game_ID, g.Game_Played, g.Season_ID, g.Game_DateTime AS datum, g.GameType_ID, g.Home_Team_ID, t1.TeamName AS hometeam, t1.Team_Shirt, g.Away_Team_ID, t2.TeamName AS awayteam, t2.Team_Shirt, g.Home_Score_FT, g.Away_Score_FT, CASE WHEN (g.Home_Score_FT>g.Away_Score_FT) THEN 'thuis' WHEN (g.Home_Score_FT=g.Away_Score_FT) THEN 'gelijk' WHEN (g.Home_Score_FT<g.Away_Score_FT) THEN 'uit' end AS winner FROM af_games g, af_teams t1, af_teams t2 WHERE g.Home_Team_ID =31 AND g.Game_Played = 'Y' AND g.Home_Team_ID= t1.Team_ID AND g.Away_Team_ID= t2.Team_ID ORDER BY datum ASC;
|