🏠 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

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.