简体   繁体   English

SQL:如何在特定时间内找到包含特定字母的所有数据?

[英]SQL: How is it possible to find all data that contain a specific letter in it a specific amount of time?

I have a table full of city names and I need to find all the citys that contain the letter "a" at least five times.我有一张满是城市名称的表格,我需要找到所有包含字母“a”的城市至少五次。 So far I got:到目前为止,我得到了:

SELECT stadt.Name 
FROM stadt
WHERE stadt.Name LIKE '%a%

But this shows me all the citys with an "a".但这向我展示了所有带有“a”的城市。 I need to have a code where I am going to get a table with only citys that have 5 x "a" in its name.我需要有一个代码,我将在其中获得一张只有名称中有 5 x“a”的城市的表格。

For exactly five a's, you want to check that there are 5 and not 6:对于恰好 5 个 a,您要检查是否有 5 个而不是 6 个:

WHERE stadt.Name LIKE '%a%a%a%a%a%' AND
      stadt.Name NOT LIKE '%a%a%a%a%a%a%'

Or, use regular expressions:或者,使用正则表达式:

WHERE stadt.Name REGEXP '^([^a]*a[^a]*){5}$'
  

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM