NULLIF(exp1, exp2)
- exp1값과 exp2값이 동일하면 NULL을 그렇지 않으면 exp1을 반환
- CASE WHEN expr1 = expr2 THEN NULL ELSE expr1 END
Test
select count(1) from customers; --10
select count(NULLIF(postalcode, '')) as cnt
from customers; --10
select count(NULLIF(postalcode, '12209')) as cnt
from customers; --9
select count(
case when postalcode = '' then null
else postalcode
end
) as cnt
from customers; --10
select count(
case when postalcode = '12209' then null
else postalcode
end
) as cnt
from customers; --9
테이블정보는 아래 글 참고
https://jieun0113.tistory.com/127
Reference
http://www.gurubee.net/lecture/1880
728x90
반응형
'DataBase > PostgreSQL' 카테고리의 다른 글
[PostgreSQL] Sequence 시작값 변경 (0) | 2020.03.06 |
---|---|
[PostgreSQL] COALESCE 함수 (Null 체크) (1) | 2019.09.05 |
[PostgreSQL] Table Data를 JSON타입으로 만들기 (1) | 2019.08.12 |
[PostgreSQL] SCHEMA CREATE, ALTER, DROP (0) | 2019.06.11 |
[PostgreSQL] Import CSV File Into Table (0) | 2019.06.11 |
댓글