SQL Challenge: Find Customers with Higher Latest vs Average Order Amount

🚀 Advanced SQL Challenge (Data Analyst Level) If you can solve this cleanly, you're interview-ready 👇 💡 Scenario: You have an "orders" table: - order_id - customer_id - order_date - amount 👉 Task: Write a query to find customers whose latest order amount is higher than their average order amount. ⚠️ Constraints: - Only consider customers with at least 3 orders - Handle duplicate order_date correctly (latest = max date, but ties possible) - Output: - customer_id - latest_order_amount - avg_order_amount --- 🔥 Bonus (real challenge): - Solve using window functions only (no subqueries) - Then rewrite using CTEs - Optimize for large datasets (millions of rows) --- 💭 Why this matters: This tests: - Window functions - Aggregation logic - Real-world thinking (not just syntax) Most candidates fail here — not because SQL is hard, but because thinking in data is. 👇 Drop your query. I’ll review the best ones. #SQL #DataAnalytics #AdvancedSQL #DataAnalyst #InterviewPrep #Analytics #LearnSQL

  • No alternative text description for this image

To view or add a comment, sign in

Explore content categories