select case when cuisine_type ='Korean' then '한식'
when cuisine_type in ('Japanese','Chinese') then '아시아'
else '기타' END "음식타입",
cuisine_type
from food_orders
1. 다음의 조건으로 배달시간이 늦었는지 판단하는 값을 만들어주세요.
주중 : 25분 이상
주말 : 30분 이상
문제 조건이 다음과 주어 졌을때
select order_id,
restaurant_name,
day_of_the_week,
delivery_time,
case when day_of_the_week = 'Weekday' then if(delivery_time>24, 'Late','On-time')
when day_of_the_week = 'Weekend' then if(delivery_time>29, 'Late','On-time')
end '지연여부'
from food_orders
답안을 이렇게 작성하였다.
2. 음식점의 총 주문수량과 주문 금액을 연산하고, 주문 수량을
기반으로 수수료 할인율 구하기
(할인조건
수량이 5개 이하 -> 10%
수량이 15개 초과, 총 주문금액이 3000000 이상 ->0.5%
이 외에는 일괄 1%)
문제 조건이 다음과 같이 주어졌을 때,
SELECT restaurant_name,
case when total_quantity <= 5 then 0.1
when total_quantity >15 and total_price >= 300000 then 0.005
else 0.01 end ratio_of_add
FROM
(
select restaurant_name,
sum(quantity) total_quantity,
sum(price) total_price
from food_orders
group by 1
) a
답안을 작성하였다.

기본적으로 공부한 이미지를 직접 가져와서 사용하지는 않지만 가장 좋은 설명의 예시인거 같아 들고 왔다.
기본 형태
-- LEFT JOIN
select 조회 할 컬럼
from 테이블1 a left join 테이블2 b on a.공통컬럼명=b.공통컬럼명
-- INNER JOIN
select 조회 할 컬럼
from 테이블1 a inner join 테이블2 b on a.공통컬럼명=b.공통컬럼명
1. [실습] 한국 음식의 주문별 결제 수단과 수수료율을 조회하기
(조회 컬럼 : 주문 번호, 식당 이름, 주문 가격, 결제 수단, 수수료율)
*결제 정보가 없는 경우도 포함하여 조회
문제 조건이 다음과 같이 주어졌을 때,
SELECT f.order_id,
f.restaurant_name,
f.price,
p.pay_type,
p.vat
From food_orders f left join payments p on f.order_id = p.order_id
where cuisine_type = 'Korean'
이렇게 답안을 작성하였다.
2. 식당별 평균 음식 주문 금액과 주문자의 평균 연령을 기반으로 Segmentation 하기
- 평균 음식 주문 금액 기준 : 5,000 / 10,000 / 30,000 / 30,000 초과
- 평균 연령 : ~ 20대 / 30대 / 40대 / 50대 이상
문제 조건이 다음과 같이 주어졌을 때,
SELECT restaurant_name,
price_avg,
age_avg,
case when price_avg <= 5000 then 'price_group1'
when 5000 < price_avg and price_avg <=10000 then 'price_group2'
when 10000 < price_avg and price_avg <=30000 then 'price_group3'
else 'price_group4' end 'price_group',
case when 0 < age_avg and age_avg <= 29 then 'age_group1'
when 30 < age_avg and age_avg <= 39 then 'age_group2'
when 40 <age_avg and age_avg <= 49 then 'age_group3'
else 'age_group4' end 'age_group'
FROM
(
SELECT f.restaurant_name,
avg(f.price) price_avg,
avg(f.food_preparation_time) age_avg
From food_orders f inner join payments p on f.order_id = p.order_id
group by 1
) a
ORDER BY restaurant_name ASC