MYSQL 我的查询的通配符问题

MYSQL Wildcard issue for my query

我遇到了 mysql 通配符的问题。 给出的是以下 table:

id | name
--------------
1  | Marcel
2  | Marcel2
3  | Marcel3

现在我需要知道 table.

中有多少名为 Marcel 的条目
SELECT id FROM 'users' WHERE name LIKE 'Marcel#' 
--gives me **0** results

SELECT id FROM 'users' WHERE name LIKE 'Marcel_' 
-- gives me just **1** result (**3** would be the solution)

我可以使用什么查询来确定 name + nr 在 table 中出现的频率?

使用%通配符:

SELECT id FROM `users` WHERE name LIKE 'Marcel%'

SqlFiddleDemo

%   A substitute for zero or more characters 
_   A substitute for a single character

所以你的:

SELECT id FROM 'users' WHERE name LIKE 'Marcel_' gives me just 1 result (3 would be the solution)

可能是错误的,请参阅:SqlFiddleDemo 因为它给你 Marcel2Marcel3 (除非你有尾随空格,我在你提供的例子中看不到)

像“%Marcel%”这样的名称应该适合您。