Skip to content

Commit 63f8b37

Browse files
authored
Update 05-query-unpivot.md
1 parent f15cfa3 commit 63f8b37

File tree

1 file changed

+17
-15
lines changed

1 file changed

+17
-15
lines changed

docs/en/sql-reference/10-sql-commands/20-query-syntax/05-query-unpivot.md

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ FROM ...
2424
Where:
2525
* `<value_column>`: The column that will store the values extracted from the columns listed in `<column_list>`.
2626
* `<name_column>`: The column that will store the names of the columns from which the values were extracted.
27-
* `<column_list>`: The list of columns to be unpivoted, separated by commas.
27+
* `<column_list>`: The list of columns to be unpivoted, separated by commas. You can optionally provide aliases for the column names using AS or just a string literal.
28+
2829

2930

3031
## Examples
@@ -57,21 +58,22 @@ INSERT INTO unpivoted_monthly_sales VALUES
5758
SELECT *
5859
FROM unpivoted_monthly_sales
5960
UNPIVOT (amount
60-
FOR month IN (jan, feb, mar, apr));
61+
FOR month IN (jan as 'Jan', feb AS 'Feb', mar 'MARCH', apr));
6162
```
6263

6364
Output:
6465
```sql
65-
+-------+-------+--------+
66-
| empid | month | amount |
67-
+-------+-------+--------+
68-
| 1 | jan | 10400 |
69-
| 1 | feb | 8000 |
70-
| 1 | mar | 11000 |
71-
| 1 | apr | 18000 |
72-
| 2 | jan | 39500 |
73-
| 2 | feb | 90700 |
74-
| 2 | mar | 12000 |
75-
| 2 | apr | 5300 |
76-
+-------+-------+--------+
77-
```
66+
┌──────────────────────────────────────────────────────┐
67+
│ empid │ month │ amount │
68+
├─────────────────┼──────────────────┼─────────────────┤
69+
1 │ Jan │ 10400
70+
1 │ Feb │ 8000
71+
1 │ MARCH │ 11000
72+
1 │ apr │ 18000
73+
2 │ Jan │ 39500
74+
2 │ Feb │ 90700
75+
2 │ MARCH │ 12000
76+
2 │ apr │ 5300
77+
└──────────────────────────────────────────────────────┘
78+
79+
```

0 commit comments

Comments
 (0)