Topfolio
Career TracksMicro Free CoursesTask CoursesPracticeInterview PracticeWork ExperienceProjects
Career TrackBlog
Support
Dashboard
Career TracksMicro Free CoursesTask Courses
SQL & Python
Interview Prep
Work ExperienceProjectsResume Feedback
CertificatesMy OrdersRefer & Earn
Join Community

Navigation

Dashboard
Learn
Career TracksMicro Free CoursesTask Courses
Practice
SQL & PythonInterview Prep
Career
Work ExperienceProjectsResume Feedback
My Stuff
CertificatesMy OrdersRefer & Earn
Join Community
Topfolio

Learn data analytics online. Real skills, real projects, real community.

courses

  • Career Tracks
  • Work Experience
  • Best Data Analyst Course in India
  • SQL Fundamentals
  • SQL Advanced
  • Python for Data
  • Micro Free Courses

practice

  • SQL Fundamentals Interview Test
  • SQL Advanced Coding Test
  • All Practice Tests

resources

  • How to Become a Data Analyst
  • SQL Interview Questions
  • Data Analyst Salary Guide
  • Free Datasets for Practice
  • SQL vs NoSQL Guide
  • Data Analyst vs Data Engineer vs Data Scientist

employers

  • Enterprise Screening
  • AI Proctoring Demo
  • Volume Pricing
  • Employer Portal

company

  • About
  • Terms
© 2026 Topfolio. All rights reserved.Made with ❤️ for aspiring analysts
Topfolio
Career TracksMicro Free CoursesTask CoursesPracticeInterview PracticeWork ExperienceProjects
Career TrackBlog
Support
Dashboard
Career TracksMicro Free CoursesTask Courses
SQL & Python
Interview Prep
Work ExperienceProjectsResume Feedback
CertificatesMy OrdersRefer & Earn
Join Community

Navigation

Dashboard
Learn
Career TracksMicro Free CoursesTask Courses
Practice
SQL & PythonInterview Prep
Career
Work ExperienceProjectsResume Feedback
My Stuff
CertificatesMy OrdersRefer & Earn
Join Community

Monthly Cohort Retention

advanced~15 min40 pts
📊 View Insights

Problem

Compute cohort retention: for each customer signup-month (first invoice), how many of that cohort were active in month 0, month 1, month 2, and month 3 thereafter.

Schema: Customer

ColumnType
CustomerIdINTEGER (PK)
FirstNameTEXT NOT NULL
LastNameTEXT NOT NULL
CompanyTEXT
CountryTEXT
EmailTEXT NOT NULL
SupportRepIdINTEGER (FK → Employee)

Schema: Invoice

ColumnType
InvoiceIdINTEGER (PK)
CustomerIdINTEGER (FK)
InvoiceDateTIMESTAMP NOT NULL
BillingCountryTEXT
TotalNUMERIC(10,2) NOT NULL

Requirements:

  • Cohort = month of customer's first invoice (YYYY-MM)
  • For each cohort, output: CohortMonth, CohortSize, M0_Active, M1_Active, M2_Active, M3_Active
  • "Active in month N" = the customer has at least one invoice in (cohort_month + N months)
  • Only include cohorts of at least 3 customers
  • Sort by CohortMonth ascending
CTEMultiple CTEsWindow FunctionsCohort AnalysisRetentionDate ArithmeticPIVOTGoogleFlipkart
📊
📊 View Question Telemetry & Insights
Failure rate, silent bug autopsy & optimal query construction
Inspect →

Master SQL & Data Analytics

Ready to take your skills to the next level? Enroll in our comprehensive Data Analyst Career Track to master SQL, Python, Excel, and Power BI.

Explore the 12-Week Data Analyst Career Track

Related questions

  • Extract Email Domainsintermediate
  • Number Tracks Within Albumsintermediate
  • Rank Artists by Album Countintermediate
  • Dense Rank Tracks by Priceintermediate
  • Compare Invoice Dates with LEAD/LAGintermediate
  • Running Total of Invoice Amountsintermediate
  • Segment Customers into Quartilesintermediate
  • Basic CTE: Artist Album Countsintermediate
SQL Editor

Run your code to see the result here.

Topfolio

Learn data analytics online. Real skills, real projects, real community.

courses

  • Career Tracks
  • Work Experience
  • Best Data Analyst Course in India
  • SQL Fundamentals
  • SQL Advanced
  • Python for Data
  • Micro Free Courses

practice

  • SQL Fundamentals Interview Test
  • SQL Advanced Coding Test
  • All Practice Tests

resources

  • How to Become a Data Analyst
  • SQL Interview Questions
  • Data Analyst Salary Guide
  • Free Datasets for Practice
  • SQL vs NoSQL Guide
  • Data Analyst vs Data Engineer vs Data Scientist

employers

  • Enterprise Screening
  • AI Proctoring Demo
  • Volume Pricing
  • Employer Portal

company

  • About
  • Terms
© 2026 Topfolio. All rights reserved.Made with ❤️ for aspiring analysts