我有以下 MySQL 命令,它使用足球队最近 6 场比赛填充表格:
insert into lastxgames
select team, matchdate, hometeam, awayteam, fthg, ftag
from (
select
team, soccerdata.matchdate, hometeam, awayteam, fthg, ftag,
@teamCounter:=IF(@prevHome=team,@teamCounter+1,1) teamCounter,
@prevHome:=team
from soccerdata
join (
select distinct matchdate, hometeam team
from soccerdata
union
select distinct matchdate, awayteam
from soccerdata
) allgames on soccerdata.matchdate = allgames.matchdate
and (soccerdata.hometeam = allgames.team or soccerdata.awayteam = allgames.team)
join (select @teamCounter:=0) t
order by team, soccerdata.matchdate desc
) t
where teamCounter <= 6
order by team, matchdate desc;
我想从 C# 程序中运行它,但是当我这样做时,查询失败,因为 @ 符号被用作查询参数,而不是按照 MySQL 的预期方式处理(MySQL 变量?)。
在我的 C# 程序中,我只是声明一个字符串来保存查询并将其添加到 MySqlCommand:
string insertCommand = @"insert into lastxgames...";
using (MySqlCommand cmdInsert = new MySqlCommand(insertCommand, dcConnection))
{
cmdInsert.ExecuteNonQuery();
}
有没有办法让 C# 忽略 @ 符号,以便 @teamCounter 和 @prevHome 不被视为查询参数?