
* 겪고 있는 문제 상황을 최대한 자세하게 작성해주세요.
* 문제 해결을 위해 어떤 시도를 해보았는지 구체적으로 함께 알려주세요.
1.
select substring(if(email like '%gmail%', replace(email, 'gmail', '@gmail'), email), 10) "이메일 도메인",
count(customer_id) "고객 수",
avg(age) "평균 연령"
from customers
group by 1
여기서 sub함수 안에 이프문이 들어가고, 10이 들어가는데 sub구조는 원래 칼럼, 시작위치, 글자수인데 시작위치가 생략되고 10은 가장 긴 이메일 주소의 글자수를 나타낸 건가요?
sub구문이 저렇게 구성된 이유가 궁금합니다!
2.
select order_id,
price,
quantity,
case when quantity>1 then price/quantity
when quantity=1 then price end "음식 단가"
from food_orders
쿼리를 아래처럼 if로 바꾸었을 때 틀린 이유가 궁금합니다.
select order_id,
price,
quantity,
if(quantity=1,price=price,price=price/quantity) "음식단가"
from food_orders

맞는 해설


