diff --git a/select_from_world_tutorial.sql b/select_from_world_tutorial.sql index 0870b81..492a8e0 100644 --- a/select_from_world_tutorial.sql +++ b/select_from_world_tutorial.sql @@ -129,6 +129,21 @@ SELECT name, CASE WHEN continent='Oceania' THEN 'Australasia' ; + +-- 11. (Added as on 2025) +-- Greece has capital Athens. +-- Each of the strings 'Greece', and 'Athens' has 6 characters. +-- Show the name and capital where the name and the capital have the same number of characters. +-- You can use the LENGTH function to find the number of characters in a string +-- For Microsoft SQL Server the function LENGTH is LEN + + +SELECT name, capital + FROM world + WHERE LENGTH(name) = LENGTH(capital); + + + -- 12. -- Show the name and the continent - but substitute Eurasia for Europe and Asia; substitute America - for each country in North America or South America or Caribbean. Show countries beginning with A or B @@ -141,6 +156,18 @@ SELECT name, CASE WHEN continent IN ('Europe','Asia') THEN 'Eurasia' ; +-- 12. (Added as on 2025) +-- The capital of Sweden is Stockholm. Both words start with the letter 'S'. +-- Show the name and the capital where the first letters of each match. Don't include countries where the name and the capital are the same word. +-- You can use the function LEFT to isolate the first character. +-- You can use <> as the NOT EQUALS operator. + + +SELECT name, capital +FROM world +where left(name, 1) = left(capital, 1) and name <> capital; + + -- 13. -- Put the continents right... @@ -162,6 +189,22 @@ ORDER BY name ; +-- 13. (Added as on 2025) +-- Equatorial Guinea and Dominican Republic have all of the vowels (a e i o u) in the name. They don't count because they have more than one word in the name. +-- Find the country that has all the vowels and no spaces in its name. +-- You can use the phrase name NOT LIKE '%a%' to exclude characters from your results. +-- The query shown misses countries like Bahamas and Belarus because they contain at least one 'a' + +SELECT name + FROM world +WHERE name LIKE '%a%' + AND name LIKE '%e%' + AND name LIKE '%i%' + AND name LIKE '%o%' + AND name LIKE '%u%' + AND name NOT LIKE '% %'; + +