我一直试图声明一个整数变量,但它只是不起作用。我的问题是:

DECLARE @count INT
SET     @count = 5633

SELECT count(matchid)
FROM   `matches`
WHERE   id = @count

我收到此错误:
Error Code: 1064. You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'DECLARE @count INT
SET     @count = 5633

请帮忙:)

最佳答案

根据MySQL manual,声明只允许在开始…结束块,必须在开始处。你还忘记了每行末尾的分号。这应该对你有用:

SET @count = 5633;

SELECT count(*)
FROM matches
WHERE id = @count;

COUNT(*)在某些情况下更快。

07-24 09:49
查看更多