我想在数据库中搜索有多少人的名字是“我是史蒂文”
我想用他们的三列搜索用户表
名字 第二个名字 姓
当我看到结果时,我想对它们进行排序,名字匹配在前,在后,姓在后。
他们在mysql中的任何命令都解决了这个难题
最佳答案
select
if (firstname like 'i am steven%', 4,
if(secondname like 'i am steven%', 2,
if (lastname like 'i am steven%', 1, 0)
)
) as first_name_first
from
user
where
firstname like 'i am steven%' or
secondname like 'i am steven%' or
lastname like 'i am steven%'
order by first_name_first desc;
关于mysql - 当搜索需要更具体时,如何在 MySQL 中使用 like 函数或在 mysql 中运行 LIKE 命令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4801515/