🏠 Главная
Бенчмарки
📊 Все бенчмарки 🦖 Динозавр v1 🦖 Динозавр v2 ✅ Приложения To-Do List 🎨 Творческие свободные страницы 🎯 FSACB - Ультимативный показ 🌍 Бенчмарк перевода
Модели
🏆 Топ-10 моделей 🆓 Бесплатные модели 📋 Все модели ⚙️ Режимы Kilo Code
Ресурсы
💬 Библиотека промптов 📖 Глоссарий ИИ 🔗 Полезные ссылки
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.