ในบทความนี้จะเป็นซีรี่ย์ใหม่ของเรา ที่จะนำโจทย์ SQL ของสาย Data มาให้ลองฝึกกัน
ใครยังไม่คล่องเรื่องนี้ หรือกำลังฝึกเขียน SQL อยู่ให้ทำโจทย์เยอะ ๆ จะได้คล่อง ๆ นะคะ ^^
อยากฝึกโจทย์ Data แนวไหนอีก ? ทักมาบอกทีมงานเราได้ที่ Post นี้เลย – ทีม Datayolk
เลือกอ่านเฉพาะหัวข้อ -
เกี่ยวกับตัวโจทย์
สำหรับโจทย์ของบทความนี้ เราจะเก็บ Data set (SQL DB) ไว้ในแพลตฟอร์ม Replit ตามลิ้งค์ด้านล่างซึ่งสามารถเข้าไปดูชุดข้อมูล และกด Run example เพื่อเริ่มทำโจทย์ได้เลย
โจทย์: Sale Dataset
เฉลยทั้งหมด: Github
โดยมี Data Dictionary ดังนี้
| order_id | Integer | PK |
| customer_id | Integer | |
| order_date | Date |
| product_id | Integer | PK |
| product_name | String | |
| unit_price | Integer |
| order_id | Integer | PK |
| product_id | Integer | FK |
| quantity | Integer |
| customer_id | Integer | PK |
| customer_name | String | |
| city | String | |
| orders_count | Integer |
| payment_id | Integer | PK |
| order_id | Integer | |
| payment_method | String | |
| amount | Floating Point |
| payment_id | Integer | PK |
| product_name | String | |
| expiration_date | Datetime |
Q1: Retrieve all customers from Mora city
Q2: Retrieve the latest order for each customer
Q3: Get the total number of orders for each customer
Q4: Calculate the running total of sales for each product over time
Q5: Retrieve the product names and their prices from the “products” table, where the price is less than $20
Q6: Find the highest order amount and the corresponding customer
Q7: Retrieve the payment methods and their amounts from the “Payments” table where the total amount is less than $200
Q8: Calculate the average order count per city
Q9: Find the top 5 customers with the highest total order amount
Q10: List all products along with the total quantity sold
Q11: Calculate the payment method with the highest total amount
Q12: Calculate the total revenue from the “orders” table by multiplying “quantity” and “unit_price” columns
Q13: Retrieve the product names and their prices from the “products” table, where the price is between $20 and $50
Q14: Calculate the percentage of total sales for each payment method
Q15: Delete all records from the “expired_products” table where the expiration date is in the past
Q16: Find the product names with expiration dates before the year 2023
Q17: Retrieve the latest order for each product
Q18: Retrieve the total amount of payments made by each customer
Q19: Calculation the customers who have made the highest total payments
Q20: Rank products based on their total revenue
ภาพหน้าปกจาก Michael Dziedzic on Unsplash
อยากมาทำงานสาย Data ใช่มั้ย?
เรามี Workshop Data Interview ที่จะช่วยคุณเตรียมพร้อมสำหรับการสัมภาษณ์งาน ผ่านการทำ Case Interview




