🏠 ホーム
ベンチマーク
📊 すべてのベンチマーク 🦖 恐竜 v1 🦖 恐竜 v2 ✅ To-Doリストアプリ 🎨 クリエイティブフリーページ 🎯 FSACB - アルティメットショーケース 🌍 翻訳ベンチマーク
モデル
🏆 トップ10モデル 🆓 無料モデル 📋 すべてのモデル ⚙️ 🛠️ Kilo Code モード
リソース
💬 💬 プロンプトライブラリ 📖 📖 AI用語集 🔗 🔗 有用なリンク
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.