我正在尝试创建以下过程,该过程是从其他服务器导出的,但是出现错误。
CREATE PROCEDURE `spGetWorkHistoryByEmployeeID`(pEmployeeID int, pStartIndex int, pCount int)
BEGIN
DECLARE LowerBound INT;
DECLARE UpperBound INT;
DECLARE rownum INT;
SET LowerBound = ((pStartIndex - 1) * pCount) + 1;
SET UpperBound = ((pStartIndex - 1) * pCount) + pCount;
SELECT
rank, JobNumber, EarliestDate, LatestDate, BillableHours
FROM
(SELECT
*, @rownum:=@rownum + 1 AS rank
FROM
(SELECT
j.JobNumber, s.EarliestDate, s.LatestDate, s.BillableHours
FROM
service s
LEFT JOIN Job j ON s.JobID = j.JobID
WHERE
s.EmployeeAssignedID = pEmployeeID
AND s.LatestDate < NOW()
ORDER BY s.LatestDate DESC) d, (SELECT @rownum:=0) r) m
WHERE
rank >= LowerBound
AND rank <= UpperBound;
END
错误说: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 'rank FROM ( SELECT j.JobNumber, s.EarliestDate, s.LatestDat' at line 2
MySql Workbench在工具提示为SELECT
的第一个"SELECT" is not valid at this position for this server version, expecting '(', WITH
下显示摆动。
这是MySql Community Server 8.0.12。
有什么想法吗?该过程存在于不同的服务器上并且运行良好。
更新:问题已解决!显然v.8.0.2 RANK
开始是保留字。
我从中复制数据库的服务器是较旧的版本。谢谢@尼克!