🏠 Home
Benchmark Hub
📊 All Benchmarks 🦖 Dinosaur v1 🦖 Dinosaur v2 ✅ To-Do List Applications 🎨 Creative Free Pages 🎯 FSACB - Ultimate Showcase 🌍 Translation Benchmark
Models
🏆 Top 10 Models 🆓 Free Models 📋 All Models ⚙️ Kilo Code
Resources
💬 Prompts Library 📖 AI Glossary 🔗 Useful Links
advanced

Complex Time-Series Analysis with SQL

#sql #data-analysis #window-functions

Solve a retention analysis problem using advanced window functions.

Write a SQL query to calculate the cohort retention rate for a subscription service. The input is a table of user logs (user_id, log_date, action). Your query must calculate the percentage of users who return in the 1st, 2nd, and 3rd months after their initial signup. Use window functions such as LAG, LEAD, and FIRST_VALUE to achieve this without using self-joins. Handle the scenario where a user churns and returns, ensuring they are counted based on their latest cohort.