본문 바로가기
DB

[MySQL] Invalid use of group function

by foreverever 2019. 10. 25.
반응형

SELECT NAME, count(NAME) as 'count'
from ANIMAL_INS 
where count(NAME) > 1
group by NAME;

 

위의 경우 'Invalid use of group function' 에러 발생

집계함수인 count와 where절은 같이 사용하지 못하기 때문

 

다음과 같이 변경

 

SELECT NAME, count(NAME) as 'count'
from ANIMAL_INS 
group by NAME
having count(NAME) > 1

 

having은 where기능과 같으면서, 집계함수 사용가능

반응형