我有一张桌子,上面有一张国家的列表。假设其中一个国家是“马其顿”。
如果搜索“共和国”,哪条SQL查询会返回“made”记录?
我相信在linq中它会是这样的
var countryToSearch = "Republic of Macedonia";
var result = from c in Countries
where countryToSearch.Contains(c.cName)
select c;现在,上面查询的SQL等价物是什么?
如果是另一种方式(即数据库存储了国家名称的长版本),下面的查询应该可以工作:
Select * from country
where country.Name LIKE (*Macedonia*)但我不知道如何才能扭转这一局面。
附注:表中的国家/地区名称始终为国家/地区名称的简称
发布于 2012-05-11 18:56:50
您可以使用CHARINDEX来实现这一点。
Select * from country
where CHARINDEX(country.Name, 'Republic of Macedonia') > 0发布于 2012-05-11 18:51:52
只需颠倒运算符(并修复语法)
Select * from country
where 'Republic of Macedonia' LIKE CONCAT('%',country.Name,'%')发布于 2018-10-20 12:07:07
对于SQLite,可以将表(mytable)中的表字符串(mysubstring)列与任意更大的测试字符串进行比较:
select * from mytable where instr('Somewhere substring is here', mytable.mySubstring) > 0
https://stackoverflow.com/questions/10549929
复制相似问题