I have a csv file uploaded to an S3 bucket which I pick up with AWS Glue then query using Athena. The CSV table is in the format below:
| Item | Country | Category | 2017 | 2018 | 2019 | 2020 |
|---|---|---|---|---|---|---|
| Item1 | CA | Network | 128 | 129 | 130 | 129 |
| Item2 | CA | Desktop | 128 | 129 | 130 | 129 |
| Item3 | CA | Apps | 128 | 129 | 130 | 129 |
I want to convert that format into:
| Item | Country | Category | Year | Value |
|---|---|---|---|---|
| Item1 | CA | Network | 2017 | 128 |
| Item1 | CA | Network | 2018 | 129 |
| Item1 | CA | Network | 2019 | 130 |
| Item1 | CA | Network | 2020 | 129 |
| Item2 | CA | Desktop | 2017 | 128 |
| Item2 | CA | Desktop | 2018 | 129 |
| Item2 | CA | Desktop | 2019 | 130 |
| Item2 | CA | Desktop | 2020 | 129 |
| Item3 | CA | Apps | 2017 | 128 |
| Item3 | CA | Apps | 2018 | 129 |
| Item3 | CA | Apps | 2019 | 130 |
| Item3 | CA | Apps | 2020 | 129 |
How do I accomplish that using SQL in Athena?
I tried this but it doesn't work for me: Simple way to transpose columns and rows in SQL?
Any help is appreciated. Thanks!