I want to store comparisons between items in a mysql table. For example, I have the following three items:
- id: 1, Name: Item A, comparisionScore: 1
- id: 2, Name: Item B, comparisionScore: 2
- id: 3, Name: Item C, comparisionScore: 3
Which means while comparing, the item whose comparisonScore is larger is better. However this method fails when I want to insert a new item to the table, which is better than Item A and worse than Item B, let’s say Item D. So I can do the following because I don’t have to store only integers:
- id: 1, Name: Item A, comparisionScore: 1
- id: 2, Name: Item B, comparisionScore: 2
- id: 3, Name: Item C, comparisionScore: 3
- id: 4, Name: Item D, comparisionScore: 1.5
The worst thing is that since we can’t know the number of new items to be added, there is not enough number for this purpose. For example, by dividing the range by 2, the result can be the following:
- id: 1, Name: Item A, comparisionScore: 1
- id: 2, Name: Item B, comparisionScore: 2
- id: 3, Name: Item C, comparisionScore: 3
- id: 4, Name: Item D, comparisionScore: 1.5
- id: 5, Name: Item E, comparisionScore: 1.75
- id: 6, Name: Item F, comparisionScore: 1.875
- id: 7, Name: Item G, comparisionScore: 1.9375
- id: 8, Name: Item H, comparisionScore: 1.96875 …
If the Item Z is better than the Item A and worse than the Item H, there is no double value that can Z take between 1.9999… and 2.
So the thing is what else method can I use to store comparison data between Items in MySQL data?
I should be able to answer when a user asks which one is better Item A or Item D by looking that table.
Instead of starting out with comparison scores of 1, 2, 3; give much larger integer values like 10,000, 20,000, 30,000. Then you have some room to insert values in the middle.
To answer your last question, when you’re trying to insert a comparison score between 12,384 and 12,385, you have to renumber all of the comparison scores first, so that you have a spot to put the newest comparison score.
The numbers are only meaningful for sorting, so you can change them anytime you wish.