使用mssql的"LIMIT"附近的语法不正确 [英] Incorrect syntax near 'LIMIT' using mssql
问题描述
我正在尝试从数据库中检索一些数据,这些数据必须是得分最高的代理商的前10名.
I'm trying to retrieve some data from the database, which need to be the top 10 of the agents with the highest score.
我的查询:
SELECT AgentScores.agentID,
AgentScores.totalScore,
Agents.firstname,
Agents.lastname
FROM AgentScores
INNER JOIN Agents ON AgentScores.AgentId=Agents.Agent_id
ORDER BY AgentScores.totalScore DESC
LIMIT 10
内部联接正在工作.我已经找到了SELECT TOP 10
sql语句,但是..我想要分数最高的10个代理,而不是前10个ID.如您所见,我正在对totalscore进行订购.
The inner joins are working. I've found the SELECT TOP 10
sql statement but.. I want the 10 agents with the highest score and not the first 10 id's. As you can see I'm ordering on the totalscore.
有人知道如何解决此问题吗?
Anyone has a clue how to fix this?
错误:Array ( [0] => Array ( [0] => 42000 [SQLSTATE] => 42000 [1] => 102 [code] => 102 [2] => [Microsoft][ODBC Driver 11 for SQL Server][SQL Server]Incorrect syntax near 'LIMIT'. [message] => [Microsoft][ODBC Driver 11 for SQL Server][SQL Server]Incorrect syntax near 'LIMIT'. ) )
谢谢!
推荐答案
您必须使用TOP子句而不是LIMIT
You have to use TOP clause instead of LIMIT
SELECT TOP 10 AgentScores.agentID, AgentScores.totalScore, Agents.firstname, Agents.lastname FROM AgentScores INNER JOIN Agents ON AgentScores.AgentId=Agents.Agent_id ORDER BY AgentScores.totalScore DESC
这篇关于使用mssql的"LIMIT"附近的语法不正确的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!