gpt4 book ai didi

php - 使所需的匹配数直接对应于列的char_length

转载 作者:行者123 更新时间:2023-11-29 11:59:03 24 4
gpt4 key购买 nike

我有一个有效的 SELECT 语句。不过,我想补充一些东西。我想使所需的匹配数直接与“输入”列的 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;

这应该将您的匹配限制为所需的值

关于php - 使所需的匹配数直接对应于列的char_length,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32682273/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com