我正在尝试运行以下 SQL 代码,该代码会生成过去 3 天的平均问题。但是,我收到 #1111 invalid use of group function 错误
。不知道我哪里出错了。即使我删除了该组,这仍然存在。请帮忙。
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';
谢谢 视频
最佳答案
在 avg 函数中使用 sum 函数会导致组函数无效使用错误。sum 函数仅返回一个值,单个值的平均值没有意义。
关于mysql - #1111 SQL 中 Group 函数的使用无效 : Concept?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21251929/