Issue Note
Table name from Subquery [SQL]
jhleeatl
2024. 3. 21. 17:35
I was looking for the column "age" from table B, but when I used "b.age", it resulted in an error.
Error code
SELECT a.cuisine_type,
a.price,
할인률,
b,age,
a.price-(price*할인률) 'after_discount'
FROM
(
SELECT a.cuisine_type,
a.price,
b.age,
if(b.age>50,(b.age-50)*0.005,0) '할인률'
from food_orders a left join customers b on a.customer_id=b.customer_id
) a
order by 할인률 desc
The error occurred because the new query retrieves data from the subquery, so it couldn't find table B as all the data is sourced from subquery A.