Answer the question
In order to leave comments, you need to log in
How to make a simple request?
Something to see the heat in the central part strongly "presses" on the brain. It seems like a simple task, but I don’t even know which side to approach ...
There is a table that stores the intervals VALUES and price:
From | Before | Price
0 | 5 | 100
6 | 10 | 200
11| 20 | 300
etc.
The conditions are such that there will be no intersecting gaps in the tables
Task: How to choose a series in which the VALUE will be in the intervals greater than FROM and less than or equal to TO
It sounds simple BUT somehow it does not add up for me
Answer the question
In order to leave comments, you need to log in
SELECT `price` FROM `table` WHERE `from`< 'value' AND `to`>='value'
The first method is also good, but in fact only one boundary can be used for disjoint sets.
CREATE TABLE IF NOT EXISTS `test1` (
`minVal` int(11) NOT NULL,
`maxVal` int(11) NOT NULL,
`price` int(11) NOT NULL AUTO_INCREMENT,
PRIMARY KEY (`price`),
UNIQUE KEY `froms` (`minVal`),
UNIQUE KEY `fr2` (`minVal`,`maxVal`)
) ENGINE=MyISAM;
EXPLAIN SELECT *
FROM `test1`
WHERE minval <=42000
ORDER BY minval DESC
LIMIT 1
EXPLAIN SELECT *
FROM `test1`
WHERE minval <=42000
AND maxval >=42000
The most correct would be to use
SELECT a FROM b WHERE c BETWEEN value1 AND value2
select * from tbl where VALUE >2 and VALUE <=10
a little more detail please. The text is not very clear what exactly you want to get.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question