0

Im trying to make a table with dynamic columns.

I have this table. This is just simplified, in other instances these may have more values instead of 3.

         name         
----------------------
 Fall
 Medication 
 Wander
(3 rows)

I am trying to get this result. I need to separate the values into columns.

  Fall  | Medication | Wander 
--------+------------+--------
(0 rows)
kimdasuncion12
  • 319
  • 2
  • 4
  • 17

2 Answers2

0

You need to PIVOT the table. Unfortunately MySQL (unlike Oracle http://www.oracle.com/technetwork/articles/sql/11g-pivot-097235.html) doesn't have a PIVOT operator, but there are workarounds it seems. MySQL pivot table

leonardseymore
  • 533
  • 5
  • 20
0

You might try one of the crosstab() functions in newer PostgreSQL. See https://www.postgresql.org/docs/current/static/tablefunc.html (F.35.1.2 and F.35.1.4). It allowes you to specify a query that has row-names (those create rows), categories (that create columns) and values (that populate the inside part of the table.

The variant with 2 queries can be especially useful since it allows you to specify the columns you want to use with a seperate query.

prinsarian
  • 31
  • 3