"at most one record can be returned by this subquery" 毫秒访问错误 sql

"at most one record can be returned by this subquery" Error in ms access sql

我正在使用 ms access 数据库,但在执行 ms access 查询时出现此类错误 "at most one record can be returned by this subquery"。

查询是-

SELECT AccNumber, SimpleLoanBal, (select sum(MonthlyCollection) from Trans group by AccNumber) as Mo FROM Trans

请告诉我如何解决它

您可以改用 correlated 子查询:

select t.AccNumber, t.SimpleLoanBal, 
      (select sum(t1.MonthlyCollection) from Trans t1 where t.AccNumber = t1.AccNumber) as Mo 
from Trans t;

然而,简单的 group by 也应该有效:

select AccNumber, SimpleLoanBal, sum(MonthlyCollection) as Mo 
from Trans 
group by AccNumber, SimpleLoanBal;