Answer the question
In order to leave comments, you need to log in
Storing combinations?
I'm not sure I phrased the question exactly, but that's the gist of it.
Let's assume there is a certain object at which 10 fields and in each field there can be 100 various unique values.
For example, the COLOR field can have 100 values, the next SIZE field can have 100 values, and so on.
The employee must be given the opportunity to set certain combinations. For example, he can set that for COLOR = red and SIZE = 20mm and DENSITY = 5 we set a certain discount of 5%. These combinations must be stored in the database. It is not known in advance how many there will be.
Maybe a 5% discount will be provided in general for all possible combinations, or maybe for one or maybe for 10,000. An employee can, for example, specify ALL for 5 fields and include all values. What is the best way to store such data?
Answer the question
In order to leave comments, you need to log in
if the length of the limit combination fits into the capacity of the maximum integer type of the database, then it's trite:
3rd color out of 10 6th size out of a hundred, 2nd age group out of ten:
1052 ... why not 2063? because we count from zero.
If the options don’t fit anywhere like: 356 option 4789065 scheme 195 subgroup 56 group 9879879 vector 987987987 space, etc., etc., then ... we write it into a string separated by commas and make a hash from it ... any sensible one. Collisions - handled separately.
ANY_HFUNC("356,4789065,195,56,9879879,987987987");
https://en.wikipedia.org/wiki/List_of_hash_functions
We store the discount calculation formula with field names and criteria for a specific position in a separate table.
When calculating the total cost, we check the matches of the criteria according to the discount table, and, if any, we multiply the total cost for this particular position by the result of the discount formula.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question