简体   繁体   English

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

[英]SQL Syntax Error - Multiple Count Multiple Criteria - MS ACCESS

First question... 第一个问题......

I've been researching this site and found a SQL that should help me...but I'm getting an error that I can't solve. 我一直在研究这个网站,发现了一个应该帮助我的SQL ......但是我收到了一个我无法解决的错误。 Find below SQL and Error: 查找下面的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;

Error: The SELECT statement includes a reserved word or an argument name that is misspelled or missing, or the punctuation is incorrect. 错误:SELECT语句包含拼写错误或缺失的保留字或参数名称,或者标点符号不正确。 (Error 3141) (错误3141)

My expectations from this query is this one: 我对此查询的期望是这样的:

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

Letters should be my fld1 names and the other numbers should be a count on how much field has accepted,rejected and cancelled status... 信件应该是我的fld1名称,其他数字应该是一个字段已经接受,拒绝和取消状态的数量......

Expressions in the SELECT statement need to be separated by commas. SELECT语句中的表达式需要用逗号分隔。 You are missing commas between the column expressions: 列表达式之间缺少逗号:

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;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM