我在 mysql
中有一个表,其中包含名为 type
的列。内容如下
Type
Test 12
Test abc
start 1
start abcd
end 123
现在我想选择type
以Test
开头的记录
预期结果:
Test 12
Test abc
但是我得到了要么
测试 12 或空结果
我试过如下:
select * from table where type = 'Test 12'
select * from table where type = '%Test%'
select * from table where type = '%Test'
正确的sql
语句应该是什么。
最佳答案
如果你想做部分匹配,你需要 LIKE
运算符:
SELECT * FROM table WHERE type LIKE 'Test%'
关于mysql - 在 where 子句 mysql 查询中使用子字符串的正确方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46411733/