Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions select_from_world_tutorial.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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...
Expand All @@ -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 '% %';





Expand Down