Skip to content

Pivot and melt #644

@aljazerzen

Description

@aljazerzen

One thing SQL lacks is a idiom of converting:

date status transaction
2022-01-01 live 10
2022-01-01 test 20
2022-01-02 live 5
2022-01-02 test 30
2022-01-03 live 25

.. into ..

date live test
2022-01-01 10 20
2022-01-02 5 30
2022-01-03 25 null

.. and back.

There is many names for this, let's list them here:

The problem has some unknowns which are treated differently by the functions above:

  • what to do with unused columns?
  • what to do with duplicated values?
  • how to name the new columns?

Related comment #300 (comment)
Could be implemented as: https://stackoverflow.com/questions/69263964/how-to-pivot-in-postgresql
Would solve: https://old.reddit.com/r/SQL/comments/viumd0/bigquery_how_to_aggregate_data/

Currently I don't have capacity to tackle all these, so I'm just opening a tracking issue.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions