Access(SQL) - Count distinct fields and group by field name

时间秒杀一切 提交于 2019-12-11 10:37:00

问题


I am in the middle of making a Client a Access Database and am stuck on how to work around what im doing.

i have a table with somthing like i have a table called Observations with somithing like this

Error Identified | Error Cat | ... | So on
No               |           |     |
Yes              | Dave3     |     |
Yes              | Dave      |     |
Yes              | Dave3     |     |
Yes              | Dave5     |     |
Yes              | Dave      |     |
Yes              | Dave6     |     |
Yes              | Dave6     |     |
Yes              | Dave      |     |

I want to count the number of occurrences that each [Error Cat] where [Error Identified] is yes

so it would bb

Error Cat | Count |
Dave      |   3   |
Dave3     |   2   |
Dave5     |   1   |
Dave6     |   2   |

What is the Access SQL for this to happen

I tried so hard but it just wont run the SQL Please help.


回答1:


SELECT ErrorCat, COUNT(*) totalCount
FROM tableName
WHERE ErrorIdentified = 'YES'
GROUP BY ErrorCat


来源:https://stackoverflow.com/questions/13504991/accesssql-count-distinct-fields-and-group-by-field-name

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!