我有一个使用 MySQL session 变量的查询(注意@rank 变量)
SELECT Rank, UserId, CurrentVDOT
FROM
(
SELECT @rank := @rank + 1 AS Rank, UserId, MaxVDOT AS CurrentVDOT
FROM
(
SELECT UserId, MAX(VDOT) AS MaxVDOT
FROM
(
SELECT U.UserId, U.VDOT
FROM
(
SELECT UserId, MAX(Created) AS Created
FROM UserVDOT
GROUP BY UserId
) G
INNER JOIN UserVDOT U
ON U.UserId = G.UserId
AND U.Created = G.Created
) M
GROUP BY UserId
ORDER BY MaxVDOT DESC
) R, (SELECT @rank := 0) foo
) F
WHERE F.UserId = @UserId;
如果我尝试针对 C# MySQL 连接器执行此操作,它会尝试告诉我需要将 @rank 声明为输入参数变量。
有什么办法解决这个问题吗?
谢谢。
最佳答案
Hello Allison!
I was facing the same problem recently, but I found that by default, the SQL connection disables the use of variables in queries. To solve this problem you can enable the connection string as follows:
连接字符串:
server=192.168.0.0;password=root;User Id=root;Persist Security Info=True;database=my_db;Allow User Variables=True
您必须输入连接参数 Allow User Variables=True 才能使其正常工作。
I hope I've helped.
Hiago Takaki
关于c# - 可以在 C# 连接器中使用 MySQL @session 变量吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16348028/