Timedora
Free Online Flashcard Deck

SQL Cohort Retention and Window Functions Free Online Flashcards

Study SQL Cohort Retention and Window Functions with 12 free online flashcards. Review key terms, definitions, and concepts with this interactive flashcard deck.

12 cards
01
Front

How is cohort retention percentage calculated?

Back

Cohort retention is the number of active users from a cohort divided by its original size, multiplied by 100. Count each user at most once per activity month.

02
Front

What does ROWS BETWEEN 2 PRECEDING AND CURRENT ROW include?

Back

ROWS BETWEEN 2 PRECEDING AND CURRENT ROW includes up to three rows, including the current row. It is not necessarily a three-calendar-month period if months are missing.

03
Front

How does RANK() handle ties?

Back

RANK() assigns tied rows the same rank and leaves gaps after ties. For example, ranks can go 1, 1, 3.

04
Front

What does OVER do in a SQL window function?

Back

OVER defines the window used for a calculation across related rows while retaining each row in the result, unlike GROUP BY, which collapses rows.

05
Front

How does DENSE_RANK() differ from RANK() after a tie?

Back

DENSE_RANK() assigns tied rows the same rank without leaving gaps after ties. For example, ranks can go 1, 1, 2.

06
Front

What does LAG() access in an ordered partition?

Back

LAG() accesses a previous row in the ordered partition. Subtracting LAG(amount) from the current amount gives the change from the previous row.

07
Front

How do window ordering and outer ordering differ?

Back

PARTITION BY divides rows into groups for window calculations, and the window ORDER BY sets their calculation sequence. The query’s outer ORDER BY sorts the final output.

08
Front

How should monthly activity be counted for cohort retention?

Back

Deduplicate activity to one user per activity month before counting active users. This ensures multiple events by one user in that month count only once.

09
Front

What does filtering ROW_NUMBER() to values at most 3 ensure?

Back

ROW_NUMBER() assigns each row a unique sequence number. Filtering it to values at most 3 returns at most three rows per partition.

10
Front

Why specify a frame for an ordered rolling aggregate?

Back

An ordered aggregate window’s default frame generally produces a running result through the current row and its peers. Specify a frame deliberately for rolling calculations.

11
Front

How can a CTE help when filtering window results?

Back

A CTE declared with WITH can organize a multi-step query. An outer query can then filter calculated window results.

12
Front

How can a retention query include months with zero activity?

Back

A query built from recorded activity returns months with activity. To show zero-activity months, generate cohort-month pairs from a calendar and left join the counts.