Data Analytics

SQL - Advanced Analytical Queries

Cohort analysis, funnels, retention, KPI calculations, pivot queries, optimization

20 interview questionsยท
Senior
1

In a cohort analysis, what is the main role of the first touch date?

Answer

The first touch date allows grouping users into cohorts based on when they first interacted with the product. This temporal segmentation is essential for comparing the behavior of user groups acquired at different periods and identifying trends or performance changes over time.

2

Which window function should be used to calculate the number of days between a user's first and last activity?

Answer

The FIRST_VALUE and LAST_VALUE functions with an OVER clause allow retrieving the first and last values of a column within a defined window respectively. Combined with DATEDIFF or date subtraction, they enable calculating a user's active lifespan without requiring multiple subqueries.

3

How to build a monthly retention table with SQL using cohorts based on the signup month?

Answer

Building a retention table requires first identifying each user's cohort via DATE_TRUNC on the signup date, then calculating the number of months elapsed between the cohort and each activity. The GROUP BY on these two dimensions and a COUNT DISTINCT of active users provide the complete table.

4

To analyze a 4-step conversion funnel (visit โ†’ signup โ†’ activation โ†’ purchase), which SQL approach is most robust?

5

How to calculate the monthly churn rate in SQL for a subscriber base?

+17 interview questions

Master Data Analytics for your next interview

Access all questions, flashcards, technical tests, code review exercises and interview simulators.

Start for free