replace(바꿀컬럼, 현재 값, 바꿀 값)select restaurant_name "원래 상점명",
replace(restaurant_name, 'Blue', 'Pink') "바뀐 상점명"
from food_orders
where restaurant_name like '%Blue Ribbon%'
//Blue Ribbon이 포함된 데이터에서 Blue > Pink 로 변경해서 조회해줌substr(조회 할 컬럼, 시작 위치, 글자 수)select addr as "원래 주소",
substr(addr, 1, 2) as "시도"
from food_orders
where addr like '%서울특별시%'
//substr(addr, 1, 2) = 서울concat(붙이고 싶은 값1, 붙이고 싶은 값2, 붙이고 싶은 값3, ...)select restaurant_name as "원래 이름",
addr as "원래 주소",
concat('[', substr(addr, 1, 2), ']',
restaurant_name) as "바뀐 이름"
from food_orders
where addr like "%서울%";select substr(addr, 1, 2) as "시도",
cuisine_type as "음식 종류",
avg(price) as "평균 금액"
from food_orders
where addr like '%서울%'
group by 1, 2;select substr(email, 10) as "도메인",
count(name) as "고객 수", avg(age) as "평균 연령"
from customers
group by substr(email, 10);select concat('[',substr(addr, 1, 2),']',restaurant_name,'(',
cuisine_type,')') as "[지역(시도)] 음식점이름 (음식종류)",
count(1) as "주문건수"
from food_orders
group by concat('[',substr(addr, 1, 2),']',restaurant_name,'(',
cuisine_type,')')IF 문
if(조건, 조건을 충족할 때, 충족하지 않을 때)
select restaurant_name,
cuisine_type "원래 음식 타입",
if(cuisine_type='korean', '한식', '기타') as "음식 타입"
from food_orders;
CASE 문
case when 조건1 then 값(수식)1
when 조건2 then 값(수식)2
else 값(수식)3
end
select restaurant_name,
cuisine_type as "원래 음식 타입",
case when (cuisine_type='korean') then '한식'
when cuisine_type in ('japanese','chinese') then '아시아'
else '기타'
end as "음식 타입"
from food_orders;
select restaurant_name,
addr as "원래 주소",
case when (addr like '%경기도%') then '경기도'
when (addr like '%특별시%' or addr like '%광역시%')
then substr(addr, 1, 5)
else substr(addr, 1, 2)
end as "변경된 주소"
from food_orders;