我试图将计数值除以子查询的值并乘以 100 以获得它的百分比。下面的代码有效......
SELECT data, rota as rt, COUNT(cliente_id) /
(
SELECT COUNT(DISTINCT cliente_id)
FROM vw_grafico
WHERE rota = rt
) * 100 ) AS porcentagem
FROM vw_grafico
WHERE WEEKDAY(data)+1 = rota
AND YEAR(data) = 2013
GROUP BY month(data)
ORDER BY data ASC
...但是,除此之外,我需要按月计算该值的平均值,这就是我的问题...当我尝试执行此操作时出现错误“无效使用组函数”:
SELECT data, rota as rt, AVG(COUNT(cliente_id) /
(
SELECT COUNT(DISTINCT cliente_id)
FROM vw_grafico
WHERE rota = rt
) * 100 ) AS porcentagem
FROM vw_grafico
WHERE WEEKDAY(data)+1 = rota
AND YEAR(data) = 2013
GROUP BY month(data)
ORDER BY data ASC
我应该怎么做才能解决这个错误?