0

I have seen similar questions but the answers did not work for me, I would like to transpose the following table :

| 2017  | 2018  | 2019  | 2020  |
|------ |------ |------ |------ |
| 358   | 1300  | 973   | 101   |

And would like to get this table :

|       | Count     |
|------ |-------    |
| 2017  | 358       |
| 2018  | 1300      |
| 2019  | 973       |
| 2020  | 101       |
a_horse_with_no_name
  • 497,550
  • 91
  • 775
  • 843
enriqueqs
  • 29
  • 5

1 Answers1

1

Use a lateral join:

select x.year, x.count
from the_table t
  cross join lateral (
      values ("2017", 2017), ("2018", 2018), ("2019", 2019), ("2020", 2020)
  ) as x(count, year)

Online example

a_horse_with_no_name
  • 497,550
  • 91
  • 775
  • 843