카운트

Googling/postgresql

[postgreSQL] 카운트 쿼리 쓸 때 알아두면 좋은 것 (null, limit)

1. 카운트 쿼리에 사용되는 데이터가 null 일 경우 건수에 포함되지 않는다. 이 점을 활용하여 (case when ~ then 1 else null end) 활용 필터링이 가능하다. count(1), count(*), count(column) 모두 실행계획과 실행시간이 동일하니, column 쓸 때만 null로 개수 빠지는지 확인만 하면 된다. --null 상관없이 전체 건수를 셈 SELECT count(*) FROM board; SELECT count(1) FROM board; --contents 중 null 인 데이터를 빼고 셈 SELECT count(title) FROM board; --contents 중 null 인 데이터를 빼고 중복 제거하여 셈 SELECT count(distinct tit..

날개단
'카운트' 태그의 글 목록