I’m looking to create a system where users specify shipping prices for their items. The variables I need to cover are the weight band (from in grams to in grams), the price and the countries covered. From this data I can calculate shipping cost by referencing the customers country and the total weight of the basket.
My first thought is something like this:
id from_weight to_weight price us ca gb fr es de it
------------------------------------------------------------------
1 0g 499g 1.99 Y Y N N N N N
2 500g 999g 2.99 Y Y N N N N N
3 1000g 1999g 4.99 Y Y N N N N N
4 2000g 2999g 7.99 Y Y N N N N N
5 0g 499g 4.99 N N Y Y Y Y Y
6 500g 999g 6.99 N N Y Y Y Y Y
7 1000g 1999g 9.99 N N Y Y Y Y Y
8 2000g 2999g 14.99 N N Y Y Y Y Y
However the plan would be to add more and more country options. This would mean adding more columns each time. Is this the best way to structure this kind of data. Any other suggestions
normally it is preferred practice to leave the table structure the same, and just add rows to cater for the case that you illustrated. (there are reasons such as optimisation where you can deviate from this)
I would suggest at looking up “3rd Normal Form”, if your database complies with the rules to be in 3rd normal form then, you generally end up with a lot less maintenance and easier extendibility down the track.
this is how you would query the data