🏠 Startseite
Vergleiche
📊 Alle Benchmarks 🦖 Dinosaurier v1 🦖 Dinosaurier v2 ✅ To-Do-Listen-Apps 🎨 Kreative freie Seiten 🎯 FSACB - Ultimatives Showcase 🌍 Übersetzungs-Benchmark
Modelle
🏆 Top 10 Modelle 🆓 Kostenlose Modelle 📋 Alle Modelle ⚙️ Kilo Code
Ressourcen
💬 Prompt-Bibliothek 📖 KI-Glossar 🔗 Nützliche Links
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.