M
M
MasterCopipaster2020-06-02 16:12:27
MySQL
MasterCopipaster, 2020-06-02 16:12:27

How to compose query in mysql to find range between text?

Help me write a request for this field

`cca` varchar(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL,

There, the content in the column is text with ranges through -

|cca |
|-------|
|360-530|
|360-600|
|360-530|
|360-530|
|360-530|

I want to search in this column for a line in which the range lies between 360 and 530
That is, I should get everything except the second record - but I don’t know how to make a search query in a text field, please help.
Yes, you can't change the column type.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
O
Omar2002, 2020-06-02
@MasterCopipaster

You can use a stored function - something like this:

drop function if exists checkRange;
 
DELIMITER //
 
CREATE FUNCTION checkRange(strRange varchar, from int, to int) RETURNS bool
   DETERMINISTIC
BEGIN
    DECLARE left INT;
    DECLARE right INT;
   
    SELECT strRange REGEXP ... INTO left
 
    SET result = ...;
 
    RETURN (result); 
END//
 
DELIMITER ;

....

SELCET * FROM table WHERE checkRange(randeColumn, 360, 530)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question