我有一张这样的表:
-- users
+----+--------+--------+
| id | f_name | l_name |
+----+--------+--------+
| 1 | Jack | Smith |
| 2 | Peter | Hall |
| 3 | John | Price |
+----+--------+--------+
这是我的疑问:
SELECT u.*,
match(f_name) against(:input) f_name_order,
match(l_name) against(:input) l_name_order,
match(f_name, l_name) against(:input) both_order,
FROM users u
WHERE match(f_name, l_name) against(:input)
ORDER BY both_order * 4 DESC, l_name_order * 2 DESC, f_name_order DESC
LIMIT 20;
现在我想在输入为john pri
时选择表格的最后一行。我当前的查询并不匹配。我怎么能这样做?
答案 0 :(得分:0)
你可以使用concat和
select u.*
from users u
where concat(f_name, ' ', l_name) like concat('%', :input, '%')