我有一个数据,要计算类别的百分比份额(“文本”列),但是我想从计算中排除空白,并要按比例计算“月份”(文本列)
我的查询:
SELECT Category, Count(Category) AS CountOfCategory, Count([Category])/DCount("*","[Tablename]") AS MyPercent
FROM [Tablename]
GROUP BY Category;
查询的当前示例结果如下所示。
我的桌子看起来像这样
| Month Text | Category |
|------------|----------|
| Dec'18 | A |
| Nov'18 | A |
| Dec'18 | A |
| Nov'18 | C |
| Dec'18 | A |
| Nov'18 | C |
| Dec'18 | B |
| Nov'18 | C |
请帮助。
答案 0 :(得分:0)
您的查询与您的数据示例不匹配,但我想此查询应该有帮助:
SELECT a.[Month Text], a.Category, Count(a.Category),
Count(a.Category)/
(
SELECT Count(b.Category)
FROM yourtablename AS b
WHERE b.[Month Text] = a.[Month Text]
)
FROM yourtablename AS a
WHERE a.Category Is Not Null
AND a.Category<>""
GROUP BY a.[Month Text], a.Category;