SQL语法错误 - 多个计数多个标准 - MS ACCESS

时间:2014-01-09 17:46:05

标签: sql ms-access syntax

第一个问题......

我一直在研究这个网站,发现了一个应该帮助我的SQL ......但是我收到了一个我无法解决的错误。在下面找到SQL和错误:

SELECT field1,
   Sum(IIf(status = "Accepted", 1, 0)) AS [field1_Accepted]
   Sum(IIf(status = "Rejected", 1, 0)) AS [field1_Rejected]
   Sum(IIf(status = "Cancelled", 1, 0)) AS [field1_Cancelled]
FROM tbl1
GROUP BY field1;

错误:SELECT语句包含拼写错误或缺失的保留字或参数名称,或者标点符号不正确。 (错误3141)

我对此查询的期望是:

field1/accepted/rejected/cancelled
a/1/2/3
b/2/3/5
c/2/3/4

信件应该是我的fld1名称,其他数字应该是一个字段已经接受,拒绝和取消状态的数量......

1 个答案:

答案 0 :(得分:3)

SELECT语句中的表达式需要用逗号分隔。列表达式之间缺少逗号:

SELECT field1,
   Sum(IIf(status = "Accepted", 1, 0)) AS [field1_Accepted], -- <<== Here
   Sum(IIf(status = "Rejected", 1, 0)) AS [field1_Rejected], -- <<== Here
   Sum(IIf(status = "Cancelled", 1, 0)) AS [field1_Cancelled]
FROM tbl1
GROUP BY field1;