Case
ํน์ ์กฐ๊ฑด์ ๋ฐ๋ผ ๋ฐ์ดํฐ๋ฅผ ๊ตฌ๋ถํ์ฌ ์ ๋ฆฌํ ๋ ์ฌ์ฉํ๋ค.
case
when ์กฐ๊ฑด then ์กฐ๊ฑด์ ์ฐธ์ผ ๊ฒฝ์ฐ
else ์กฐ๊ฑด์ ์ฐธ์ด ์๋ ๊ฒฝ์ฐ
end
์ํ ์ ์๊ฐ 70์ ์ด์์ด๋ฉด "A-CLASS", 70์ ๋ณด๋ค ๋ฎ์ผ๋ฉด "B-CLASS"๋ก ํ์ํ๋ ค๊ณ ํ๋ค.
select subject, score,
case
when score >= 70 then 'A-CLASS'
else 'B-CLASS'
END as 'CLASS'
from MATH;
SUBSTRING
๋ฌธ์์ด์ ์ํ๋ ๊ธธ์ด๋งํผ ์ชผ๊ฐ ๋ค.
SUBSTRING(๋ฌธ์์ด ํ๋, ์์์ธ๋ฑ์ค, ๋ถํฐ ๋ช ๊ฐ)
A_table
DAY | NUMBER |
---|---|
2021-09-12 | 123123 |
2019-04-24 | 4353123 |
2021-11-10 | 54676 |
1999-01-02 | 2435346 |
2021-07-29 | 789456 |
2023-12-30 | 18971 |
2000-05-05 | 621587 |
... | ... |
... | ... |
... | ... |
select SUBSTRING(DAY, 1, 4) as A_YEAR from A_table
A_YEAR |
---|
2021 |
2019 |
2021 |
1999 |
2021 |
2023 |
2000 |
... |
... |
... |
SUBSTRING_INDEX
๋ฌธ์์ด์ ์ด๋ ํ ๊ธฐ์ค์ผ๋ก ์ชผ๊ฐ๊ณ ์ํ๋ ์ธ๋ฑ์ค ๊ฐ ๊ฐ์ ธ์ค๊ธฐ
SUBSTRING_INDEX(๋ฌธ์์ด ํ๋, ์ชผ๊ฐค ๊ธฐ์ค, ๋ช ๋ฒ์งธ ์ธ๋ฑ์ค)
B_table
email | NUMBER |
---|---|
abcd3479@naver.net | 123123 |
dfjkl888@daum.com | 4353123 |
kaka123@hanmail.com | 54676 |
dev09897@kakao.net | 2435346 |
hho124@naver.net | 789456 |
23nnb@naver.net | 18971 |
vvb45@daum.com | 621587 |
... | ... |
... | ... |
... | ... |
select SUBSTRING_INDEX(email, '@', 2) as domain from B_table
domain |
---|
naver.net |
daum.com |
hanmail.com |
kakao.net |
naver.net |
naver.net |
daum.com |
... |
... |
... |