Design DB to calculate prize based on distance of cities

I am working on a side project to calculate the prize of the service based on the city distances.

In my prize table I have values like below:

CATEGORY DISTANCE VALUE
Category A < 100 km 10EUR
Category A From 100 km to 300 km 50 EUR
Category A > 300 km 100 EUR

My idea is to prepare a DB structure like below:

CATEGORY DISTANCE_FROM DISTANCE_TO VALUE
Category A 0 100 10
Category A 100 300 50
Category A 300 x 100

Is this the right approach? I am also wondering how to later get the correct value if for example distance is 150 km?

The project will be build in Django, any help appreciated.

If you know there is no overlap in distance ranges, you could use only the DISTANCE_FROM column and find the applicable row using

SELECT TOP 1 
... 
WHERE DISTANCE_FROM < 150 
ORDER BY DISTANCE_FROM DESC
Back to Top