'How to solve # 7 in SQLZOO select names section

All:

I am learnig SQL now, but stuck at #7 of

http://sqlzoo.net/wiki/SELECT_names

Bahamas has three a - who else?

Find the countries that have three or more a in the name

Thanks

sql


Solution 1:[1]

Try this query:

SELECT name
FROM world
WHERE LEN(name) - LEN(REPLACE(name,'a', '')) > 2

Solution 2:[2]

I'm trying to solve this lecture with regular expressions but couldn't match this correctly.

regexp '(.*[a]){3,}'

Should match 3 or more 'a', which it does but:

"Sao Tomé and Príncipe" with 2 a's is matched by LIKE '%a%a%a%' which is the correct answer.

Im curious what's going wrong here?

Solution 3:[3]

SELECT name
FROM world
WHERE LENGTH(name) - LENGTH(REPLACE(lower(name),'a', '')) >= 3

Solution 4:[4]

This is worked for me:

SELECT name FROM world WHERE name LIKE '%a%a%a%';

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2 Sebastian
Solution 3 Unheilig
Solution 4 ouflak