🏠 홈
벤치마크
📊 모든 벤치마크 🦖 공룡 v1 🦖 공룡 v2 ✅ 할 일 목록 앱 🎨 창의적인 자유 페이지 🎯 FSACB - 궁극의 쇼케이스 🌍 번역 벤치마크
모델
🏆 톱 10 모델 🆓 무료 모델 📋 모든 모델 ⚙️ 킬로 코드 모드
리소스
💬 프롬프트 라이브러리 📖 AI 용어 사전 🔗 유용한 링크
advanced

Complex SQL Data Analysis

#sql #data-analysis #window-functions #optimization

Solve a multi-step data analysis problem using advanced SQL window functions, CTEs, and performance optimization.

You are a Data Analyst. You have access to a database with three tables: 'Sales' (transaction_id, date, amount), 'Products' (product_id, category, cost), and 'Stores' (store_id, region, manager). Your task is to write a single PostgreSQL query that performs the following: 1. Calculates the running total of sales amount per store ordered by date. 2. Identifies the difference in daily sales compared to the previous day for each store (lag function). 3. Ranks the stores within each region based on their total monthly sales (dense_rank function). 4. Filters the results to show only the top-performing store for each region for the current month. 5. Explain how you would index these tables to optimize the performance of this specific query.