You have a Snowflake table 'CUSTOMER ORDERS with columns 'CUSTOMER ID', 'ORDER DATE, and 'ORDER AMOUNT. You need to calculate the cumulative sum of 'ORDER AMOUNT' for each customer, ordered by 'ORDER DATE. However, due to potential late-arriving data, you also need to implement a windowing function that resets the cumulative sum if there's a gap of more than 30 days between consecutive orders for a customer. Which SQL query best accomplishes this?

Correct Answer: C
Option C correctly uses a conditional partitioning approach. UG(ORDER DATE, 1, ORDER DATE) OVER (PARTITION BY CUSTOMER_ID ORDER BY ORDER_DATE)' calculates the previous order date for each customer. (ORDER_DATE - 1, ORDER DATE) OVER (PARTITION BY CUSTOMER ID ORDER BY ORDER DATE) > 30)' creates a boolean expression that is true when the difference between consecutive order dates exceeds 30 days. This boolean expression is then used as a secondary partition key, effectively restarting the cumulative sum whenever a gap of more than 30 days occurs. The primary partition is still 'CUSTOMER ID' , ensuring sums are calculated within each customer's order history. The ordering of 'ORDER_DATE is essential for the cumulative sum to be calculated chronologically.