匹配显示在单词中与mysql中的数字相对

时间:2015-10-14 00:55:16

标签: php mysql database mysqli

我有一个select语句试图从数据库中选择匹配项,但在得到结果后,匹配项是单词,而不是数字。

SELECT DATA ,  
"CASE WHEN data LIKE  '%one two%' THEN 2 
ELSE CASE WHEN data LIKE '%one%' THEN 1
ELSE 0
END
END
END" AS  'matches'
FROM remember
LIMIT 0 , 30

结果:

列匹配:

"CASE WHEN data LIKE  '%love%' THEN 2" ELSE CASE W...
"CASE WHEN data LIKE  '%love%' THEN 2" ELSE CASE W...
"CASE WHEN data LIKE  '%love%' THEN 2" ELSE CASE W...

预期结果:

列匹配:

2
1
0

1 个答案:

答案 0 :(得分:2)

您不需要CASE多次:

SELECT CASE WHEN data LIKE  '%one two%' THEN 2 
            WHEN data LIKE '%one%' THEN 1
            ELSE 0 
            END AS  'matches'