Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/86.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Mysql #1111在SQL:概念中无效使用组函数?_Mysql_Sql_Syntax Error - Fatal编程技术网

Mysql #1111在SQL:概念中无效使用组函数?

Mysql #1111在SQL:概念中无效使用组函数?,mysql,sql,syntax-error,Mysql,Sql,Syntax Error,我正在尝试运行下面的sql代码,它将生成过去3天的平均问题。但是,我得到了#1111组函数的无效使用错误。不知道我哪里出错了。即使我通过删除组,此选项也会保持不变。请帮忙 select BookId, ChapterName, AuthorCountry, avg(sum(No_of_issues)) as last3dayavgissues from library_data where Date between (select max(Date) from library_da

我正在尝试运行下面的sql代码,它将生成过去3天的平均问题。但是,我得到了
#1111组函数的无效使用错误
。不知道我哪里出错了。即使我通过删除组,此选项也会保持不变。请帮忙

select BookId, ChapterName, AuthorCountry,
       avg(sum(No_of_issues)) as last3dayavgissues
from library_data
where Date between (select max(Date) from library_data) and
                   (select (max(Date)-3) from library_data) 
group by BookId, ChapterName 
having (AuthorCountry='US' OR AuthorCountry='DE')) 
group by BookId, ChapterName 
order by AuthorName
into outfile 'C:/output files/abc.csv'
        fields terminated by '\t'
        lines terminated by '\n';
谢谢
Avi

在avg函数中使用sum函数会导致无效使用group函数错误。sum函数只返回一个值,单个值的平均值没有意义。

您已按两次分组。我已尝试重新格式化您的查询,但在
HAVING
子句末尾似乎有一个额外的
这实际上是一个块吗一个更大的查询(因为如果是这样的话,你会向我们展示内部查询和外部查询的一部分,所以这很混乱)