카테고리 없음

[SQL] COUNT

worri-pi 2021. 8. 22. 17:06

 

기본 사용 방법 (해당 table 데이터의 총 개수 구하기)

 

select count(*) from 테이블명;

 

 

특정 조건의 데이터 개수 구하는 방법

 

select count(*) from table
where userNo='123'
select table(case when userNo='1234' then 1 end) from table
select
count(case when userNo='1234' then 1 end),
count(case when userNo='2345' then 1 end)
from table

 

 

userNo 의 데이터 종류 개수 구하는 방법 (중복을 제거하여 데이터 종류 개수를 보여줌)

 

select count(distinct userNo) from table

 

 

그리고 null 값에 대해서 더 공부가 필요한 것 같다.

https://mydb.tistory.com/218 참고하자.

728x90