🏠 Trang chủ
Benchmark
📊 Tất cả benchmark 🦖 Khủng long v1 🦖 Khủng long v2 ✅ Ứng dụng To-Do List 🎨 Trang tự do sáng tạo 🎯 FSACB - Trình diễn cuối cùng 🌍 Benchmark dịch thuật
Mô hình
🏆 Top 10 mô hình 🆓 Mô hình miễn phí 📋 Tất cả mô hình ⚙️ Kilo Code
Tài nguyên
💬 Thư viện prompt 📖 Thuật ngữ AI 🔗 Liên kết hữu ích
Advanced

SQL Window Functions Optimization

#sql #database #optimization #analytics

Write a complex SQL query using window functions to calculate moving averages and ranking without self-joins.

Given a sales table with columns (transaction_id, sale_date, amount, region), write a single SQL query that calculates the 3-day moving average of sales per region and ranks each transaction within its region by amount in descending order. Use only window functions (OVER, PARTITION BY, ROWS/RANGE) and avoid using subqueries or self-joins. Optimize for execution on a PostgreSQL database.