I would like to do a transposition to create columns from long list.
Here is the example
+-------+--------+--------+-------+ | id | typeid | type | value | +-------+--------+--------+-------+ | a0001 | 01 | sales | 10 | | a0001 | 02 | revune | 3 | | a0001 | 03 | asset | 6 | | a0002 | 01 | sales | 8 | | a0002 | 03 | asset | 2 | | a0003 | 01 | sales | 12 | | a0003 | 02 | revune | 8 | | a0003 | 03 | asset | 8 | +-------+--------+--------+-------+
Since the value in type
is enumerable, I would like to transform it into separate columns.
Here is the one I expected:
+-------+-------+---------+-------+ | id | sales | revenue | asset | +-------+-------+---------+-------+ | a0001 | 10 | 3 | 6 | | a0002 | 8 | null | 2 | | a0003 | 12 | 8 | 8 | +-------+-------+---------+-------+
I know how to do it in py/js.
I would like to know if it is possible to transpose using SQL in the database query?