I am building a data analysis tool and I need to store race odds in database. One of such odds type is called "trifecta" or "triplet" where you have to pick winning three participants in right order. As there can be up to 16 racers (but usually it is around 10) per race, this means that I have 16x15x14 different possible permutations. To store these, I made table with columns "race_id", "pos1", "pos2", "pos3" and "value" where I store only existing odds. Pos1 is the winner, pos2 is second place, pos3 is third place and value is the odds value that this particular permutation has.
This all works fairly well and I usually have about 500 permutations per race stored in db.
You still alive? Now comes the part that is causing me troubles. Occasionally I need to pull some data from db and it HAS TO BE in certain form (CSV). This is not up to me.
New format is "raceid", "perm_1_2_3", "perm_1_2_4", ... , "perm_1_2_16", "perm_1_3_2", "perm_1_3_4", ...
All columns have to exist in this new form even when I don't have them stored in db.
I am having troubles figuring out HOW should I do it. Any hints and tips are appreciated.
Here is a small sample of data in db:
raceid pos1 pos2 pos3 value
201411 1 2 6 4643.6
201411 1 2 7 2321.8
201411 1 2 9 2321.8
201411 1 3 2 9287.2
201411 1 3 4 4643.6
Edit:
I need this as:
raceid perm_1_2_3 perm_1_2_4 perm_1_2_5 perm_1_2_6 perm_1_2_7 perm_1_2_8 perm_1_2_9 perm_1_2_10 ...
201411 None None None 4643.6 2321.8 None 2321.8 None
This is a real problem and I don't expect anyone to do it for me. I am just hoping to get some hints or tips HOW should I solve this problem.