1

我正在运行以下查询:

select isnull(right(araccltid,4),'Tot') as ProdCode, count(aracid) as NumofAccounts from araccount where right(araccltid,4) 在 5109 和 5112 之间按 right(araccltid,4) 分组

使用 winSQL 并返回:

产品编号 NumofAccounts
5109 21864
5110 4206
5111 7380
5112 40075
总计 73525

我想添加一个百分比列,以便我看到:

ProdCode NumofAccounts 百分比
5109 21864 29.74
5110 4206 5.72
5111 7380 10.04
5112 40075 54.51
总计 73525 100.00

我试过这样调整脚本:

选择 isnull(right(araccltid,4),'Tot') 作为 ProdCode,count(aracid) 作为 NumofAccounts,count(aracid)/tblCount.AcctCount 作为来自 araccount 的百分比,(选择 count(aracid) 作为来自 araccount 的 AcctCount where right( araccltid,4) 在 5109 和 5112 之间)作为 tblCount 其中 right(araccltid,4) 在 5109 和 5112 之间按 right(araccltid,4) 分组并汇总

但我收到此错误:

错误:选择列表中的列 'tblCount.AcctCount' 无效,因为它既不包含在聚合函数中,也不包含在 GROUP BY 子句中。(状态:37000,本机代码:1FB8)

有什么帮助吗?

4

0 回答 0