在以下查询中,我获得了#1111的Group函数的无效使用-坦率地说,我一次又一次地检查它,没有发现任何不正确的地方。有什么我想念的吗?
让Sublime中的查询检查淫秽括号的数量是否正确并且也结婚了...
SELECT CURRENT_TIME,
s.`kickoff`,
s.`home`,s.`away`,
Sum(((i.010H+i.010A+i.1020H+i.1020A+i.2030H+i.2030A+i.3040H+i.3040A+i.4045H+i.4045A)/(count(i.home)))*100) as averageFHGHome,
sum(((case when i.010H+i.010A+i.1020H+i.1020A+i.2030H+i.2030A+i.3040H+i.3040A+i.4045H+i.4045A>0.5 then 1 else 0 end)/(count(i.home)))*100) as occurFHGHome,
sum(((case when i.010H+i.010A+i.1020H+i.1020A+i.2030H+i.2030A+i.3040H+i.3040A+i.4045H+i.4045A>1.5 then 1 else 0 end)/(count(i.home)))*100) as occur2FHGHome,
Sum(((i.4560H+i.6070H+i.7080H+i.80FTH+i.4560A+i.6070A+i.7080A+i.80FTA)/(count(i.home)))*100) as averageSHGHome,
sum(((case when i.4560H+i.6070H+i.7080H+i.80FTH+i.4560A+i.6070A+i.7080A+i.80FTA>0.5 then 1 else 0 end)/(count(i.home)))*100) as occurSHGHome,
sum(((case when i.4560H+i.6070H+i.7080H+i.80FTH+i.4560A+i.6070A+i.7080A+i.80FTA>1.5 then 1 else 0 end)/(count(i.home)))*100) as occur2SHGHome,
Sum(((i.010H+i.010A+i.1020H+i.1020A+i.2030H+i.2030A+i.3040H+i.3040A+i.4045H+i.4045A+i.4560H+i.6070H+i.7080H+i.80FTH+i.4560A+i.6070A+i.7080A+i.80FTA)/(count(i.home)))*100) as averageMG,
sum(((case when i.010H+i.010A+i.1020H+i.1020A+i.2030H+i.2030A+i.3040H+i.3040A+i.4045H+i.4045A+i.4560H+i.6070H+i.7080H+i.80FTH+i.4560A+i.6070A+i.7080A+i.80FTA>0.5 then 1 else 0 end)/(count(i.home)))*100) as occur1MG,
sum(((case when i.010H+i.010A+i.1020H+i.1020A+i.2030H+i.2030A+i.3040H+i.3040A+i.4045H+i.4045A+i.4560H+i.6070H+i.7080H+i.80FTH+i.4560A+i.6070A+i.7080A+i.80FTA>1.5 then 1 else 0 end)/(count(i.home)))*100) as occur2MG,
sum(((case when i.010H+i.010A+i.1020H+i.1020A+i.2030H+i.2030A+i.3040H+i.3040A+i.4045H+i.4045A+i.4560H+i.6070H+i.7080H+i.80FTH+i.4560A+i.6070A+i.7080A+i.80FTA>2.5 then 1 else 0 end)/(count(i.home)))*100) as occur3MG
from saturday s
inner join ITACornerNew i on s.home=i.Home
group by s.home
HAVING s.kickoff > subTIME(CURRENT_TIME, '01:45:00') and s.kickoff < CURRENT_TIME
order by s.kickoff ASC
答案 0 :(得分:1)
由于您的“淫秽括号” ,您最终获得了无效
Sum(...count(...)...)
这是聚合的聚合,而您可能正在寻找类似
的东西Sum(...)/count(...)
与您当前的问题没有直接关系,但另外,如果s.home
不是您的主键,则可能会得到不正确的结果或an error message,因为s.kickoff
和{{1} }不属于您的s.away
。而且,正如@Strawberry已经提到的那样,您应该强烈考虑重新设计group by
。