What do the two window calculations return for the city values?
The query first uses a window function to calculate grp for each customer. It then partitions the rows by that value and performs a second window calculation. Check which rows end up in each partition. What will the query return?
Predict the resultNULLMiddleAnalystData Engineer
Input data · iv_customers
| id | name | city |
|---|---|---|
| 1 | Alice | Berlin |
| 2 | Bob | Paris |
| 3 | Carol | NULL |
| 4 | Dan | Berlin |
| 5 | Eve | Paris |
Query
WITH staged AS (
SELECT id,
city,
COUNT(city) OVER (
ORDER BY id
ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW
) AS grp
FROM iv_customers
)
SELECT id,
city,
MAX(city) OVER (PARTITION BY grp) AS observed_city
FROM staged
ORDER BY id