使所需的匹配数直接对应于列的 char_length
Make number of matches required directly corresponds with char_length of column
我有一个有效的 SELECT 声明。不过,我想补充一点。我想使所需的匹配数直接对应于 'input' 列的 char_length。所以,例如:
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...
如何将 ^^^that 添加到下面的 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;
运行下面先单独查询:
SELECT @limit := 0;
然后将您的查询修改为如下所示:
SELECT response, ( input LIKE '% $text %' ) as matches, @limit := @limit + 1
FROM allData
WHERE (char_length(input) >= '$textLen'-($textLen*.1)
AND char_length(input) <= '$textLen'+($textLen*.1))
AND @limit < CEIL(CHAR_LENGTH(input) / 5)
HAVING matches > 0
AND matches = (select max(( input LIKE '% $text %' )) from allData) limit 30;
这应该将您的匹配限制为所需的值
我有一个有效的 SELECT 声明。不过,我想补充一点。我想使所需的匹配数直接对应于 'input' 列的 char_length。所以,例如:
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...
如何将 ^^^that 添加到下面的 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;
运行下面先单独查询:
SELECT @limit := 0;
然后将您的查询修改为如下所示:
SELECT response, ( input LIKE '% $text %' ) as matches, @limit := @limit + 1
FROM allData
WHERE (char_length(input) >= '$textLen'-($textLen*.1)
AND char_length(input) <= '$textLen'+($textLen*.1))
AND @limit < CEIL(CHAR_LENGTH(input) / 5)
HAVING matches > 0
AND matches = (select max(( input LIKE '% $text %' )) from allData) limit 30;
这应该将您的匹配限制为所需的值