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
[PostgreSQL] Table Data를 JSON타입으로 만들기
JSON으로 Data를 전송해야하는 경우 쿼리를 이용하여 Table Data를 JSON타입으로 만들 수 있다. Test Case drop table customers; create table customers ( customerID varchar , customerName varchar , contact..
jieun0113.tistory.com
Reference
http://www.gurubee.net/lecture/1880
NVL, NVL2, NULLIF, COALESCE
NVL NVL 함수는 NULL 값을 다른 값으로 바꿀 때 사용하며, 모든 데이터 타입에 적용이 가능하다. -- 매니저가 없는 값을 0으로 바꾸어서 출력..
www.gurubee.net
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 |
댓글