Reputation: 25
i am creating a database on MySQL which involves gambling odds (i.e 2/1 or 11/2) MySQL doesn't recognise data in this format, so how can I create a data type for these gambling odds. I can of-course put these in decimal form, however I would like to know if it is possible to store them this way?
Upvotes: 1
Views: 207
Reputation: 69829
I think storing them as decimal is the way forward, I would assume at some point you may want to do a calculation involving the odds, in which case decimal will be more convenient. You could use a lookup table to store the varchar representation as there are some quirky fractions out there, so it is not a case of finding the lowest proper fraction (e.g. 100/30, 6/4), so you could have a table like so:
Decimal | Fraction
1.5 | 2 / 3
2.0 | Evens
3.0 | 6 / 4
3.33 | 100 / 30
4.0 | 3 / 1
Upvotes: 1
Reputation: 44384
You could store the odds as a numerator/denominator pair using two fields. If you want to only use one field, the only sensible way would be using decimal form.
I recommend using the decimal value, unless you need to display the odds in a string, in which case it would probably be fine to use a numerator/denominator pair.
Upvotes: 1
Reputation: 13354
you can store them plain-text in a VARCHAR column if you have no need to use them in calculations or ORDER
ing. Or you could use two columns, one for the first part, another for the second part of the fractions.
Upvotes: 1