查询访问数据库时出错

时间:2016-01-18 13:55:26

标签: c# sql ms-access

我想弄清楚这个简单查询有什么问题。我想要总结 几列并按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

1 个答案:

答案 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