WorkbenchJ - Error: aggregates not allowed in GROUP BY clause

匿名 (未验证) 提交于 2019-12-03 02:35:01

问题:

I found a few other threads with this error message on the site but the solutions there did not seem to work for me.

This is the query I am trying to run:

SELECT      o.name as Name,      o.vrank_tav__c as Vrank,     COUNT(c.enterprise_id) AS #_users_enterprise FROM      (community_csv_james c JOIN      salesforce_data_opportunity o ON c.enterprise_id = o.enterprise_id__c) GROUP BY #_users_enterprise, Name, Vrank ORDER BY #_users_enterprise DESC; 

When I run it on SQL Workbench J, I get the following error:

SELECT      o.name as Name,      o.vrank_tav__c as Vrank,     COUNT(c.enterprise_id) AS #_users_enterprise FROM      (community_csv_james c JOIN      salesforce_data...  ERROR: aggregates not allowed in GROUP BY clause 

I've tried a few variations of this but I that promoted different error messages. How should I write this query?

Thanks!

回答1:

You are not supposed to include the results from your aggregate function (your Count()) in your group by. The count is going to be associated with a distinct name/Vrank so you would only need to group on those. That's why it's giving you that specific error.

GROUP BY Name, Vrank 

MySQL documentation for GROUP BY



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