I have a problem that is deceptively difficult! Lets say I have a DB table that looks like this:
student_id score
502 0
502 2
502 4
407 3
407 1
407 3
50 2
50 4
50 3
What I am trying to achieve is a select statement that will give me this:
502 407 50
0 3 2
2 1 4
4 3 3
So I would be doing something like a select distinct on student_id and set those as column headings. Then I want to list all the scores for each distinct student_id.
I will put this to rest and say it is not possible to do this in a single sql statement where the statement produces the column headings (in this case student_id) based on what is in the table. It seems you really do need the power of a full programming language to accomplish the task.
The end goal for me is a CSV so I will create a CSV from the table data and then write a ruby script to read the cells and create a new CSV with the column headings and data.