This question is similar to what I need to do, but the voted answer only partially solves the problem. Consider this table:
ID | TEST | RESULT
001 | AAA | +
001 | BBB | +
002 | AAA | +
003 | BBB | +
I would like output like this:
ID | AAA | BBB
001 | + | +
002 | + |
003 | | +
The solution I mentioned above provides the same data as its output, but does not "skip over" the empty columns, as for 003. Therefore, it is not possible to determine which test a + result refers to. I'm using PostgreSQL 8.4.9.
PS: Is a solution in pure SQL possible? Would this need to be coded in PL/pgSQL instead?
TESTcolumn have exactly two values ?TESThas a number of different values. I would just select the values I wanted to include withWHERE? The output I require at the moment only uses two of the possibleTESTvalues, but ideally I would like to do this in future with a few columns -- maybe up to a dozen.