Skip to content

Commit d067c45

Browse files
Create retrieving-first-instance-of-change-event-using-conditional_change_event.md
1 parent 672e22f commit d067c45

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Retrieving first instance of change event using conditional_change_event
2+
3+
CONDITIONAL_CHANGE_EVENT is a versatile Snowflake function that returns a window event number for each row when the value of the expression is different from the value in the previous row.
4+
5+
This can be a very powerful function to use when analyzing events data or time-series data. For e.g. if you need to retrieve the first `update_date` by Support Engineer per Case Status change in the following data:
6+
7+
|![Screen Shot 2024-12-04 at 9 09 14 PM](https://github.com/user-attachments/assets/bef4184b-5bbf-4a32-b95c-51666a2e4b09)|
8+
|:--:|
9+
|We need to retrieve the first `status_date` by Support Engineer per Case Status change|
10+
11+
```
12+
with support_cases as (
13+
select *
14+
, conditional_change_event (status || support_engineer) over (partition by case_number order by update_date asc) as dense_sequence
15+
from support_case
16+
)
17+
select * from support_cases
18+
qualify row_number() over (partition by case_number, dense_sequence order by update_date) = 1;
19+
```
20+
21+

0 commit comments

Comments
 (0)