V
V
Vladimir Golub2015-05-12 07:14:22
MySQL
Vladimir Golub, 2015-05-12 07:14:22

How to select from a span if one end can be 0?

For example, I send a circulation value of 1000 to the request.
The table looks like this
Start End Price
10 100 500
101 500 1000
501 600 1500
601 0 2000
How do I choose the price in this case, BETWEEN is not suitable, because there should be two ends.
Only >= and <=.

SELECT price FROM prices WHERE tirag >= start AND tirag <= end

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Rsa97, 2015-05-12
@RazerVG

WHERE `start` <= `price` AND (`end` = 0 OR `price` <= `end`)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question