在 SQL 中查找以 ___ 结尾的数据?

Finding data ending in ___ in SQL?

尝试从数据库中获取此信息:城市名称以“boro”或 'town' 结尾且平均房价等于或低于 250,000 美元的邮政编码数量。

这是我输入的内容:

select count(*) 
from zip_codes 
where city like ’%boro’ and city like ‘%town’ and average_house_value <= 250000;

并不断收到此消息:错误 1064 (42000):您的 SQL 语法有误;查看与您的 MySQL 服务器版本相对应的手册,了解在 '%boro' OR city like '%town') 和第 1 行 average_house_value <= 250000' 附近使用的正确语法

帮助?

where city like ’%boro’ and city like ‘%town’ and average_house_value <= 250000

您的查询有问题:

  1. 您应该使用标准的单引号而不是这些时髦的 字符;很可能,这就是您收到语法错误的原因

  2. 您想要以 'boro' 'town' 结尾的城市,但您编写了一个搜索以 'boro' 'town' 结尾的城市的查询两者:保证return没有行,因为没有值可以同时以两个字符串结尾

考虑:

select count(*) 
from zip_codes
where (city like '%boro' or city like '%tow') and average_house_value <= 250000

我建议为此使用正则表达式:

where city regexp '(boro|town)$' and
      average_house_value <= 250000;