Skip to content

Commit 7825e06

Browse files
Update unpivot-multiple-columns in-snowflake.md
1 parent 8c0644e commit 7825e06

File tree

1 file changed

+5
-25
lines changed

1 file changed

+5
-25
lines changed

unpivot-multiple-columns in-snowflake.md

Lines changed: 5 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -7,31 +7,11 @@ Data can be organized in different ways, for example, in a short/wide or tall/sk
77
|Transposing Wide Table into a Long Table using UNPIVOT for easier analysis|
88

99
## Example 1: Unpivot 3 Columns
10-
Suppose you have a Wide Table format Performance Ratings data as following:
11-
12-
| NAME | ACTING_RATING | ACTING COMMENTS | COMEDY RATING | COMEDY COMMENTS | MUSICAL PERFORMANCE RATING | MUSICAL PERFORMANCE COMMENTS |
13-
|--------------|---------------|-----------------|---------------|-----------------|----------------------------|------------------------------|
14-
| Groucho Marx | 4 | Awesome | 3 | Super | 4 | Really good |
15-
| Harpo Marx | 4 | Awesome | 4 | Awesome | 4 | |
16-
| Groucho Marx | 4 | | 3 | Thumbs up | 4 | Nice |
17-
| Harpo Marx | 4 | Best Acting | 4 | Nice | 4 | Best performance Award! |
18-
19-
and you need to convert it to a Long Table Format as following
20-
21-
| NAM | SKILL | SKILL_RATING | COMMENTS | SKILL_COMMENTS |
22-
|--------------|----------------------------|--------------|-------------------------|------------------------------|
23-
| Groucho Marx | ACTING_RATING | 4 | Awesome | ACTING_COMMENTS |
24-
| Groucho Marx | COMEDY_RATING | 3 | Super | COMEDY_COMMENTS |
25-
| Groucho Marx | MUSICAL_PERFORMANCE_RATING | 4 | Really good | MUSICAL_PERFORMANCE_COMMENTS |
26-
| Harpo Marx | ACTING_RATING | 4 | Awesome | ACTING_COMMENTS |
27-
| Harpo Marx | COMEDY_RATING | 4 | Awesome | COMEDY_COMMENTS |
28-
| Harpo Marx | MUSICAL_PERFORMANCE_RATING | 4 | | MUSICAL_PERFORMANCE_COMMENTS |
29-
| Groucho Marx | ACTING_RATING | 4 | | ACTING_COMMENTS |
30-
| Groucho Marx | COMEDY_RATING | 3 | Thumbs up | COMEDY_COMMENTS |
31-
| Groucho Marx | MUSICAL_PERFORMANCE_RATING | 4 | Nice | MUSICAL_PERFORMANCE_COMMENTS |
32-
| Harpo Marx | ACTING_RATING | 4 | Best Acting | ACTING_COMMENTS |
33-
| Harpo Marx | COMEDY_RATING | 4 | Nice | COMEDY_COMMENTS |
34-
| Harpo Marx | MUSICAL_PERFORMANCE_RATING | 4 | Best performance Award! | MUSICAL_PERFORMANCE_COMMENTS |
10+
Suppose you have a Wide Table format Performance Ratings that you need to covert to a Long Table format:
11+
12+
|![Copy of Untitled drawing(3)](https://github.com/user-attachments/assets/fe058626-62c3-4155-a2aa-288b6c84c798)|
13+
|:--:|
14+
|Unpivoting to convert Skill Rating and Skill Comments to a Flattened view of the data as Key-value pairs|
3515

3616
This can be achieve by using the UNPIVOT function as following
3717

0 commit comments

Comments
 (0)