🏠 Beranda
Benchmark
📊 Semua Benchmark 🦖 Dinosaurus v1 🦖 Dinosaurus v2 ✅ Aplikasi To-Do List 🎨 Halaman Bebas Kreatif 🎯 FSACB - Showcase Utama 🌍 Benchmark Terjemahan
Model
🏆 Top 10 Model 🆓 Model Gratis 📋 Semua Model ⚙️ Kilo Code
Sumber Daya
💬 Perpustakaan Prompt 📖 Glosarium AI 🔗 Tautan Berguna
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.