0
select 
    A.ACCT as acct, COUNT(TRANS_key) as payments
from 
    DEBT A 
join 
    TRANS B on B.DEBT_KEY = A.DEBT_KEY
join 
    TRANS_CODE C on C.TRANS_CODE = B.TRANS_CODE
join 
    CLIENT D on D.CLIENT_KEY = A.CLIENT_KEY
join 
    STATUS S on S.STAT_KEY = A. STAT_KEY
where 
    S.CATEGORY = 'A' and D.CLIENT_KEY = 43

错误:

无法对包含聚合或子查询的表达式执行聚合函数。

运行此程序时出现上述错误。我不确定我是否应该以不同的方式加入这些表,但我需要这个工作。

4

2 回答 2

0

尝试

select A.ACCT as acct, COUNT(TRANS_key) as payments
from DEBT A 
join TRANS B on B.DEBT_KEY = A.DEBT_KEY
join TRANS_CODE C on C.TRANS_CODE = B.TRANS_CODE
join CLIENT D on D.CLIENT_KEY = A.CLIENT_KEY
join STATUS S on S.STAT_KEY = A. STAT_KEY
where S.CATEGORY = 'A' and D.CLIENT_KEY = 43
group by A.ACCT 

您不能使用像count这样的聚合函数只返回 1 个结果和返回多个结果的选择。如果你想计算每个a.acct然后执行上述操作。

于 2012-08-10T12:23:05.183 回答
0

所有其他选择都必须分组。用这个

    select A.ACCT as acct, COUNT(TRANS_key) as payments

from DEBT A join TRANS B on B.DEBT_KEY = A.DEBT_KEY

join TRANS_CODE C on C.TRANS_CODE = B.TRANS_CODE

join CLIENT D on D.CLIENT_KEY = A.CLIENT_KEY

join STATUS S on S.STAT_KEY = A. STAT_KEY

where S.CATEGORY = 'A' and D.CLIENT_KEY = 43
GROUP BY A.ACCT
于 2012-08-10T12:24:22.720 回答