Timedora
Free Practice Quiz Question List

SQL Window Functions and Cohort Retention Online Quiz Questions

Use this free practice quiz with 10 questions to review SQL Window Functions and Cohort Retention, test your knowledge, and prepare for your next test or exam.

10 questions
01
Choose one
1 point

What is a key effect of using a window function with an OVER clause?

  1. A

    It combines each partition into a single output row, like GROUP BY.

  2. B

    It calculates across related rows while retaining each row in the result.

  3. C

    It sorts the final output but cannot calculate values.

  4. D

    It removes rows that have matching values.

02
Choose one
1 point

When rows tie on the ranking expression, how does RANK() differ from DENSE_RANK()?

  1. A

    RANK() leaves gaps after ties; DENSE_RANK() does not.

  2. B

    RANK() assigns unique numbers to ties; DENSE_RANK() leaves gaps.

  3. C

    RANK() and DENSE_RANK() both assign each tied row a unique number.

  4. D

    DENSE_RANK() leaves gaps after ties; RANK() does not.

03
Choose one
1 point

In an ordered partition, what does amount - LAG(amount) calculate for each row?

  1. A

    Add the current amount to the amount in the next row.

  2. B

    Return the average of all rows in the partition.

  3. C

    Subtract the previous row's amount from the current row's amount.

  4. D

    Subtract the current row's amount from the first row's amount.

04
Choose one
1 point

How is cohort retention percentage calculated for a particular cohort and activity month?

  1. A

    Divide the cohort size by the number of active users, then multiply by 100.

  2. B

    Divide active users by the original cohort size, then multiply by 100.

  3. C

    Divide active users by the number of activity months, then multiply by 100.

  4. D

    Subtract active users from the original cohort size, then multiply by 100.

05
Choose one
1 point

You need a deterministic unique position for each employee within a department, including when salaries tie. Which approach best meets that need?

  1. A

    Use RANK() and remove all employees with equal salaries.

  2. B

    Use DENSE_RANK() because it assigns unique numbers to ties.

  3. C

    Use ROW_NUMBER() ordered only by department.

  4. D

    Use ROW_NUMBER() ordered by salary and a stable tie-breaker such as employee_id.

06
Choose one
1 point

When calculating active users for a cohort and activity month, how should multiple events by the same user in that month be treated?

  1. A

    Count every event, even if one user has multiple events in the month.

  2. B

    Count each user once for the entire cohort, regardless of activity month.

  3. C

    Count each user once per activity month, even if they had multiple events that month.

  4. D

    Count only users who were active in every month after their cohort month.

07
Choose one
1 point

A rolling average uses ROWS BETWEEN 2 PRECEDING AND CURRENT ROW ordered by month. If some months have no rows, what does this frame describe?

  1. A

    It averages up to three rows, which may not be three consecutive calendar months.

  2. B

    It averages exactly three consecutive calendar months, even if data is missing.

  3. C

    It averages only the two preceding rows and excludes the current row.

  4. D

    It averages all rows from the start of the account's history.

08
Choose one
1 point

Within an OVER clause, what roles do PARTITION BY and ORDER BY play?

  1. A

    PARTITION BY sets the sequence; ORDER BY divides rows into groups.

  2. B

    PARTITION BY divides rows into groups; ORDER BY determines their sequence.

  3. C

    PARTITION BY removes duplicate rows; ORDER BY filters the calculation.

  4. D

    PARTITION BY sorts the final output; ORDER BY defines the frame size.

09
Choose one
1 point

A cohort-retention query based on recorded activity should also display months with zero activity. What additional approach is needed?

  1. A

    Use RANK() to add rows for missing months.

  2. B

    Replace the cohort size with zero for months without activity.

  3. C

    Use an inner join to create the missing month rows.

  4. D

    Generate a calendar of cohort-month pairs and left join the activity counts.

10
Choose one
1 point

In PostgreSQL, what does the default frame for an ordered aggregate window generally produce?

  1. A

    It always includes every row in the partition, regardless of ordering.

  2. B

    It selects only the next row in the partition.

  3. C

    It generally produces a running result through the current row and its peers.

  4. D

    It produces a fixed three-row rolling average.