Getting error: Selected non aggregate values must be part of the associate group

Database

Getting error: Selected non aggregate values must be part of the associate group

create table tbls.nousage_2 as
(SELECT a.nbr,
SUM((var1)+(var2)+(var3)+(var4)+(var5)+(var6)+(var7)+(var8)+
(var9)+(var10)+(var11)+(var12)+(var13)+(var14)+(var15)+(var16)+(var17)+(var18)+ (var19)+(var20)+(var21)) AS tot_usage,
CASE WHEN tot_usage=0 THEN 1 ELSE 0 END as mnths_no_usage
FROM tbls.nousage_1 a left join
(select * from P7P.VMS8 where month=201005) vms8
on a.nbr = vms8.nbr
GROUP BY a.nbr, tot_usage
HAVING tot_usage = 0) with data;

The table nousage_1 also has the variable tot_usage created in a similar fashion. so i tried renaming the variable in this step but that dint have any impact either...

plz help!!
1 REPLY
Junior Supporter

Re: Getting error: Selected non aggregate values must be part of the associate group

Weird select...

You must use an aggregate (MAX(), for example) for the 'mnths_no_usage' (CASE...) column.

HTH.

Cheers.

Carlos.