WorkbenchJ - 错误:GROUP BY子句中不允许聚合

时间:2016-06-03 23:54:28

标签: mysql sql group-by

我在网站上发现了一些其他错误消息,但那里的解决方案对我来说似乎不起作用。

这是我正在尝试运行的查询:

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;

当我在SQL Workbench J上运行它时,出现以下错误:

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

我尝试了一些此类变体,但我提出了不同的错误消息。我该怎么写这个查询?

谢谢!

1 个答案:

答案 0 :(得分:1)

您不应该在群组中包含您的聚合函数(您的Count())的结果。计数将与不同的名称/ Vrank相关联,因此您只需要对这些名称进行分组。这就是为什么它会给你这个特定的错误。

If basicRadioButton.Checked then
     'the totalLabel conditions now
end if

if  standardRadioButton.Checked  then
     'the totalLabel conditions now
end if

if  premiumRadioButton.Checked  then
     'the totalLabel conditions now
end if

MySQL documentation for GROUP BY