我想弄清楚这个简单查询有什么问题。我想要总结
几列并按id主键对其进行分组,然后我想使用降序排序的'TOP 1'来提取最大数量。当我添加行ORDER BY sumofTotal DESC
时,我从visual studio服务器资源管理器中收到此错误:
SELECT TOP 1 ID, SUM(K + L + M + N + AD + AR) AS sumofTotal
FROM Calculator
GROUP BY ID
ORDER BY sumofTotal DESC
答案 0 :(得分:0)
SumOfTotal不是此搜索中的列,而是列标题。
你需要:
SELECT TOP 1 ID, SUM(K + L + M + N + AD + AR) AS sumofTotal
FROM Calculator
GROUP BY ID
ORDER BY SUM(K + L + M + N + AD + AR) DESC