REPLACE, SUBSTRING, CONCATIF, CASECAST[지역] 음식점명 (음식종류) 포맷 만들기CAST()를 사용하여 문자 → 숫자, 숫자 → 문자로 변환 필요substring, avg, replace를 조합하면 종종 "data type error" 발생'123' + 10 → 오류)cast(컬럼 as decimal) 또는 cast(컬럼 as char) 사용IF, CASE, SUBSTRING을 적절히 중첩해서 사용| 기능 | 설명 | 예시 |
|---|---|---|
REPLACE() | 문자열 변경 | replace(addr, '문곡리', '문가리') |
SUBSTRING() / SUBSTR() | 문자열 자르기 | substr(addr, 1, 2) |
CONCAT() | 문자열 합치기 | concat('[', 시도, '] ', 가게이름) |
IF() | 조건문 (단일 조건) | if(cuisine_type='Korean', '한식', '기타') |
CASE | 조건문 (복수 조건) | case when ... then ... else ... end |
CAST() | 형변환 | cast(rating as decimal) |
JOIN 구문과 윈도우 함수 학습 예정select order_id,
restaurant_name,
day_of_the_week,
delivery_time,
case when day_of_the_week='Weekday' and delivery_time>=25 then 'Late'
when day_of_the_week='Weekend' and delivery_time>=30 then 'Late'
else 'On-time' end "지연여부"
from food_orders