我对这个查询有疑问
SELECT SUM(ROUND( SUM( note=3 ) / count( note=3 ) )) AS AVG, sma_famille.famille
FROM sma_notes, sma_famille, sma_agents, sma_service_activite
WHERE sma_famille.id_famille >=14
AND sma_famille.id_service =9
AND sma_notes.id_agent >=7
GROUP BY sma_famille.id_famille
我收到错误消息
#1111 - Invalid use of group function
如果有人有这种查询的经验。
这里查询的一些细节:
我像这样在没有第一个 SUM 的情况下进行查询(这是整个查询代码)
SELECT ROUND( SUM( note =3 ) / count( note =3 ) ) AS AVG, sma_famille.famille, sma_notes.id_agent
FROM sma_notes, sma_famille, sma_agents, sma_service_activite
WHERE sma_famille.id_famille >=14
AND sma_famille.id_service =9
AND sma_notes.id_agent >=7
AND sma_notes.id_agent = sma_agents.id_agent
AND sma_service_activite.id_activite = sma_notes.id_activite
AND sma_service_activite.id_famille = sma_famille.id_famille
GROUP BY sma_famille.id_famille, sma_notes.id_agent
比我得到的结果如下:
AVG | famille | id_agent
3 |BEL | 7
2 |BEL | 8
1 |BEL | 9
1 |CEL | 7
2 |CEL | 8
1 |CEL | 9
但是我的查询谁不起作用:
SELECT SUM(ROUND( SUM( note=3 ) / count( note=3 ) )) AS AVG, sma_famille.famille
FROM sma_notes, sma_famille, sma_agents, sma_service_activite
WHERE sma_famille.id_famille >=14
AND sma_famille.id_service =9
AND sma_notes.id_agent >=7
AND sma_notes.id_agent = sma_agents.id_agent
AND sma_service_activite.id_activite = sma_notes.id_activite
AND sma_service_activite.id_famille = sma_famille.id_famille
GROUP BY sma_famille.id_famille
我想得到这个结果:
AVG | famille
6 |BEL
4 |CEL
提前致谢
跟腱
干杯