
' 4-4. [실습] 복잡한 연산을 Subquery 로 수행하기 ' 를 실습할때 가장 마지막에 a라고 이름지어준 후 분홍색이랄까로 활성화되지 않고, SQL Error [1064] [42000]: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'a' 등으로 뜹니다.
별명을 지어줄 때 알아보기 쉽도록 as 를 표기하여 그 옆에 적어주고 있는데요
괄호로 묶어준 다음에는 as을 이용하여 별명지을 수 없는걸까요? 아니면 as를 사용해도 일반적으로 ""로 사용해서 별명지어주는것처럼 하지 않고 그냥 따옴표 없이 작성해야하는건가요?
여기서 a양옆에 있는 ""를 지우면 문제없이 결과가 나오는 걸로 보아 그럴 것 같긴 합니다.
그렇다면 이유가 뭔지 궁금합니다.
작성한 쿼리와 오류메시지 공유드립니다.
..
=======
<오류메시지>
SQL Error [1064] [42000]: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''a'
LIMIT 0, 200' at line 13
=====
<작성한 쿼리>
select restaurant_name,
sum_price, sum_quantity,
case when sum_quantity<=5 then 0.1
when sum_quantity>15 and sum_price>=300000 then 0.005
else 0.01 end as "dicount_rate"
from
(
select restaurant_name,
sum(price) as "sum_price",
sum(quantity) as "sum_quantity"
from food_orders
group by 1)
AS "a"
