我正在尝试显示两个队伍在比赛结果页面上显示的头对头胜利记录。这是一个累积的计数,将在每场比赛之后在竞争团队之间发生变化。我需要定义'Team'和'Opponent'变量来运行查询,但我似乎无法让它工作。 $ GameID变量通过GET方法传递,但我需要将查询的Team和Opponent变量设置为特定GameID的Team和Opponent。
SELECT @team := Team, @opponent := Opponent FROM MatchDetails2017 WHERE GameID = $GameID AND HA = 'H')
SELECT @Team, @Opponent,
COUNT(*) AS Played,
SUM(WL LIKE 'W%') AS Won,
SUM(WL LIKE 'L%') AS Lost,
SUM(WL = 'D') AS Drawn
FROM MatchDetails2017
WHERE Team = '@Team'
AND Opponent = '@Opponent'
AND GameID <= $GameID
");
答案 0 :(得分:0)
在MYSQL中分配变量:
select @var1:= column1,@var2:=column2 from yourtable;
select @var1,@var2