Md Hasibur Rahaman Md Hasibur Rahaman - 4 months ago 21
MySQL Question

get fee price in between price range start price and endprice

I have a table which hold value price range and fee something link that

+-------------+-----------+-------------+
| start_price | end_price | fees_amount |
+-------------+-----------+-------------+
| 100 | 1000 | 5.0000 |
| 1001 | 2000 | 10.0000 |
| 2001 | 3000 | 15.0000 |
+-------------+-----------+-------------+


If i input 1200 then i wont to get fees_amount
10.0000
because
1200
is between
1001-2000
slab ,

Please help me with mysql Query

Answer Source

You can use the following query using BETWEEN:

SELECT fees_amount 
FROM table_name 
WHERE 1200 BETWEEN start_price AND end_price

Another solution would be the following query:

SELECT fees_amount 
FROM table_name 
WHERE 1200 >= start_price AND 1200 <= end_price