728x90
반응형
Decode
decode(target_col,null,null,0,0,coalesce(target_col2 / target_col, 0))
Case when
case when target_col1 IS NULL then null
when target_col1 = 0 then 0
when (target_col1 is null and target_col1 != 0) then coalesce(target_col2 / target_col1,0)
ELSE
....
1. 대규모 데이터 및 복잡한 쿼리인 경우 Case when의 속도가 더 빠름.
2. Case 문은 statement 이고 decode 는 func에 해당한다.
3. Case 는 sql / pl/sql 모두 쓰이나, decode는 sql 에서만 쓰인다.
4. Case는 when 이후 조건문이 가능하지만, decode는 동일값인지 여부만 판별 가능.
decode에 비해 Case 문이 가독성이 좋으므로, 선호한다 ( 속도는 미미하지만 덤으로 )
320x100
반응형
'DB' 카테고리의 다른 글
[DB] SELECT Query VS VIEW (0) | 2024.03.05 |
---|---|
[DB] VERTICA ifnull coalesce (0) | 2024.02.29 |
[DB] postgresql recursive 재귀쿼리 (0) | 2023.12.07 |
[DB] postgresql TEXT vs VARCHAR vs JSON 타입은 언제 써야하나? (1) | 2023.11.22 |
[DB] MySQL CURRENT_TIMESTAMP (0) | 2023.10.05 |