简体   繁体   English

在mysql查询中设置变量

[英]Setting a variable in mysql query

I am trying to display the head to head win loss records for two teams to display on the game results page. 我正在尝试显示两支球队的正面对头输赢记录,以显示在游戏结果页面上。 It's a cumulative tally that will change after each match up between competing teams. 这是一个累积的计数,在各支战队之间的每场比赛之后都会改变。 I need to define the 'Team' and 'Opponent' variables to run the query, but I cant seem to get it to work. 我需要定义“ Team”和“ Opponent”变量来运行查询,但是我似乎无法使其正常工作。 The $GameID variable is passing via the GET method, but I need to set the Team and Opponent variable for my query to be the Team and Opponent for the particular GameID. $ 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
                                            ");

Assigning a variable in MYSQL: 在MYSQL中分配变量:

select @var1:= column1,@var2:=column2  from yourtable;
select @var1,@var2

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM