Courseiva
Data Transformation →hardMultiple Choice

DEA-C02 Data Transformation Practice Question

A data engineer needs to transform a large fact table by adding a column that contains the previous row's `sale_amount` partitioned by `customer_id` and ordered by `sale_date`. The table has billions of rows, and the transformation must run efficiently without shuffling data unnecessarily. Which Snowflake feature should be used to achieve this?

⚠ Common exam trap

The trap here is thinking that a self-join or correlated subquery is necessary to access a previous row, when a window function like LAG is the optimized, correct tool.

Answer choices

Why each option matters

Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.

Correct answer & explanation

✓

Use the `LAG` window function with a `PARTITION BY customer_id ORDER BY sale_date` clause.

The LAG window function is specifically designed to return a value from a preceding row within a partition. Partitioning by customer_id and ordering by sale_date ensures the immediate previous sale for each customer is correctly identified. Snowflake's optimizer can handle large datasets efficiently with window functions, avoiding the costly shuffles typical of self-joins or correlated subqueries.

Answer analysis

Option-by-option breakdown

For each option: why learners choose it and why it is or isn't the right answer here.

  • ✗

    Use a correlated subquery that selects the maximum `sale_amount` from the same table where `sale_date` is less than the current row's `sale_date`.

    Why it's wrong here

    A correlated subquery that selects the maximum sale_amount is incorrect because it retrieves the maximum value, not the previous row's value. Even if corrected to select the latest sale_date, correlated subqueries are generally inefficient for billions of rows and may not use partitioning effectively.

  • ✓

    Use the `LAG` window function with a `PARTITION BY customer_id ORDER BY sale_date` clause.

    Why this is correct

    LAG is designed to access a previous row within a window. Partitioning by customer_id and ordering by sale_date ensures the previous sale for each customer is correctly identified, and Snowflake's optimizer can leverage clustering or partitioning to reduce data movement, making it efficient for large tables.

  • ✗

    Use the `LEAD` window function with a `PARTITION BY customer_id ORDER BY sale_date` clause and then reverse the order.

    Why it's wrong here

    LEAD looks forward, not backward. Reversing the order would still require an additional sort and does not directly yield the previous row's value. This approach adds unnecessary complexity and can be less efficient than using LAG, which is purpose-built for accessing preceding rows.

  • ✗

    Use a self-join on `customer_id` where the right table's `sale_date` is less than the left table's `sale_date`, then filter to the maximum right `sale_date`.

    Why it's wrong here

    A self-join with inequality and aggregation is a classic alternative, but it typically requires a large shuffle and can be far less efficient than a window function on billions of rows. It also risks incorrect results if multiple rows share the same sale_date, and it does not guarantee the immediate previous row.

About these practice questions

This DEA-C02 question is part of Courseiva's 229-question bank — original exam-style content with full explanations and wrong-answer analysis, never real exam questions or exam dumps. Learn why practice questions differ from exam dumps →

How Courseiva writes practice questions · Editorial policy

JA

Written and reviewed by Johnson Ajibi, MSc IT Security

Senior Network & Security Engineer · founder of Courseiva

Last reviewed September 2026 · checked against the official Snowflake exam blueprint

This DEA-C02 practice question is part of Courseiva's free Snowflake certification practice question bank. Courseiva provides original exam-style practice questions with explanations, topic-based practice, mock exams, readiness tracking, and study analytics to help learners prepare for the DEA-C02 exam.