【发布时间】:2015-07-29 15:11:37
【问题描述】:
我正在尝试从数据库中检索一些数据,这些数据需要是得分最高的前 10 名代理。
我的查询:
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。正如你所看到的,我在总分上排序。
有人知道如何解决这个问题吗?
错误: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'. ) )
谢谢!
【问题讨论】:
-
"I want the 10 agents with the highest score and not the first 10 id's"- 这就是您的ORDER BY子句的用途。您没有按 ID 值排序,那为什么要根据这些值进行限制?
标签: php sql-server