#if함수 #if(수식, 참일때실행문, 거짓일때실행문)
select if(hire_date like '2005%', last_name, '2005년 입사 아님')
from employees;
#ifnull(컬럼/값, 널일때실행문)
select last_name, commission_pct, 12*salary+12*salary*commission_pct
from employees;
select last_name, commission_pct, 12*salary+12*salary*ifnull(commission_pct, 0)
from employees;
#nullif(exp1, exp2): exp1과 exp2가 같으면 null, 같지 않으면 exp1 반환
select last_name, length(last_name), first_name, length(first_name),
nullif(length(last_name), length(first_name))
from employees;
#case문: 비교할 조건이 여러개 일때 사용
case exp when 값1 then 실행문
when 값2 then 실행문
when 값3 then 실행문
else 실행문
end as '컬럼별칭'
select department_id,
case department_id when 10 then '10번 부서'
when 20 then '20번 부서' when 30 then '30번 부서'
else '이외 부서' end as '부서명'
from employees;
'MySQL은 좀 낫다면서요' 카테고리의 다른 글
MySQL #테이블 (0) | 2021.06.17 |
---|---|
MySQL #Ch6.서브쿼리 : 연습문제 (0) | 2021.06.17 |
MySQL #Ch5.함수 : 연습문제 (0) | 2021.06.17 |
MySQL #CH4. Join : 연습문제 (0) | 2021.06.16 |
MySQL #조인(Join) (0) | 2021.06.16 |