Getting count mismatch because of Nonaggregate value in group by clause.

Database

Getting count mismatch because of Nonaggregate value in group by clause.

Sel key1,key2 from
( sel name1 as key1,name as key 2,sum(x),sum(y),avg(x),
Key5
From table1 inner join table2
Where
Group by key1,key2
)
a
-- count 14000

When trying to fetch key5 getting different count.

Because I need to add that column as part of group by clause.