본문 바로가기

Category91

Table name from Subquery [SQL] 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 th.. 2024. 3. 21.
Red highlighted error [SQL] I received an error message, but the result is fine. I can't find any issues, but the SQL system highlighted the word. SELECT a.cuisine_type, a.price, discount, age, a.price-(price*discount) 'after_discount' FROM ( SELECT a.cuisine_type, a.price, b.age, if(b.age>50,(b.age-50)*0.005,0) 'discount' from food_orders a left join customers b on a.customer_id=b.customer_id ) a order by discount desc 2024. 3. 21.
Left Join & Inner Join JOIN function is used to combine two or more tables to create a single result set. JOIN typically defines the relationship between two tables based on specific conditions and combines rows accordingly. Major JOIN types include INNER JOIN, LEFT JOIN, RIGHT JOIN, and FULL JOIN. However, I am going to write only about LEFT JOIN, INNER LEFT JOIN in this posting 1. LEFT JOIN includes all rows from th.. 2024. 3. 21.
Subquery 1) When a Subquery is needed     When multiple operations need to be performed        → Determine the time value to charge the fees        → Add extra fee based on order amounts        → Calculate the final estimated delivery fee based on the applied weights    When the results of operations are needed in conditional statements        → When wanting to divide food expenses into high/medium/low .. 2024. 3. 21.
Replace Data in SQL and IF Statements String Manipulation1. REPLACE: Replace specified characters with others.2. SUBSTRING: Extract specific characters.3. CONCAT: Combine multiple strings for formatting.Conditional Statements1. IF: if(condition, value when condition is true, value when condition is false)2. CASE WHEN END: case when condition1 then value(expression)1 when condition2 then value(expression)2 else value(expressi.. 2024. 3. 20.
Calculating/Categorizing/Sorting Raw Data  Calculating ( + ) Not only addition but also multiplication and division are possible.select food_preparation_time, delivery_time, food_preparation_time + delivery_time as total_timefrom food_orders  result   Sum & Averageselect sum(food_preparation_time) total_food_preparation_time, avg(delivery_time) avg_delivery_timefrom food_orders    CountBy adding COUNT(1) or (*.. 2024. 3. 20.