28, SQLZOO to exercises SELECT names

SQLZOO written exercises SELECT names articles
www.sqlzoo.net

This tutorial uses the LIKE operator to check the name of the country, we will use the SELECT statement in the world table:
Here Insert Picture Description
name: State Name
continent: parts of Africa

1, Y is to find out the country's beginning. (% Wildcard is, can represent any character.)
SELECT name from World WHERE name like '% the Y'

2. Find the Y ending the country. ,
SELECT name from World WHERE name like '% the Y'

3. Find all the countries, whose names include the letter x.
select name from world where name like ' % X%'

4. Find all nations, for his name to land at the end.
select name from world where name like ' % land'

5. find all the countries whose names start with C as the end, ia for.
select name from world where name like ' C% IA'

6. find all the countries whose names include the letters oo.
SELECT name FROM world WHERE name LIKE ' % OO%'

7. find all the countries whose names include three or more a.
SELECT name FROM world WHERE name LIKE ' % a% a% a%'

8. identify all countries, and its name to t for the second letter. (You can use a single underline character _ as wildcard letter.)
The SELECT name from world the WHERE name like '% _t'

9. identify all the countries, whose name has two letters o, the other two being separated by the letter.
select name from world where name like ' % o__o%'

10. identify all the countries, whose name is four letters.
select name from world where name like ' ____'

11. Display all the country's name, the capital and the country's name are the same.
select name from world where name = capital

12. Display all the country's name, its capital, is the country's name plus "City". (The concat function: SQL CONCAT function for two strings together to form a single string.)
SELECT name from World WHERE Capital like the concat (name, 'City')

13. identify all the capital and its national name, and the name of the national capital have appeared.
select capital, name from world where capital like concat ( '%', name, '%')

14. identify all the capital and its national name, but the capital is an extension of the country's name. You should show Mexico City, Mexico because it is longer than their national name. You should not be displayed Luxembourg, due to its capital and the country with the same name.
select name, capital from world where capital like concat (name, '_%') and capital! = name

15. "Monaco-Ville" is the name of national merger "Monaco" and extension of the word "-Ville". Display the country's name, and the extension of the word, as capital is an extension of the country's name.
select name, replace (capital, name , '') as ext from world where capital like concat (name, '_%')

Published 38 original articles · won praise 5 · Views 6021

Guess you like

Origin blog.csdn.net/luluisntlulu/article/details/100534153
Recommended