Сделать необходимое число совпадений соответствует char_length столбца

У меня есть инструкция SELECT. Однако я хотел бы что-то добавить к этому. Я хотел бы сделать так, чтобы количество совпадений соответствовало значению char_length столбца «input». Так, например:

if (char_length(input) <= 5) { matches required is 1 } if (char_length(input) > 5 && char_length(input) <= 10) { matches required is 2 } if (char_length(input) > 10 && char_length(input) <= 15) { matches required is 3 } and ect... 

Как добавить ^^^ в инструкцию SELECT ниже?

 $text = "one"; $textLen = strlen($text); SELECT response, ( input LIKE '% $text %' ) as matches FROM allData WHERE (char_length(input) >= '$textLen'-($textLen*.1) AND char_length(input) <= '$textLen'+($textLen*.1)) HAVING matches > 0 AND matches = (select max(( input LIKE '% $text %' )) from allData) limit 30; 

Related of "Сделать необходимое число совпадений соответствует char_length столбца"