🏠 Home
Benchmark
📊 Tutti i benchmark 🦖 Dinosauro v1 🦖 Dinosauro v2 ✅ App To-Do List 🎨 Pagine libere creative 🎯 FSACB - Ultimate Showcase 🌍 Benchmark traduzione
Modelli
🏆 Top 10 modelli 🆓 Modelli gratuiti 📋 Tutti i modelli ⚙️ Kilo Code
Risorse
💬 Libreria di prompt 📖 Glossario IA 🔗 Link utili
advanced

Complex SQL Query Refactoring

#sql #database #performance #optimization

Optimize a poorly performing SQL query involving multiple joins and subqueries.

Given a hypothetical PostgreSQL schema with tables: orders (10M rows), customers (1M rows), and products (500k rows). The existing query uses five correlated subqueries and DISTINCT to calculate the lifetime value of customers who purchased electronics in the last quarter. Rewrite this query to use Common Table Expressions (CTEs) and window functions to maximize performance. Explain the execution plan differences.