Professional Documents
Culture Documents
TABLE CREATION:
At first, we have to create table named “WORLD CITY”.
Code for creating table:
create table worldcity(city varchar2(50), country varchar2(50), continent
varchar2(50), latitude number(5,2), northsouth varchar2(5), longitude
number(5,2), eastwest varchar2(5) not null);
QUERIES:
1. For all the different countries contained in the WORLDCITY
table, display their names and continent in which they are
located. Make sure that no country name is duplicated.
(Ans) select distinct country,continent from worldcity order by
country;
2. Write an SQL query to display the list of the city and country
for all the cities that begins with letter R.
(Ans) select city,country from worldcity where city like 'r%';
3. Write an SQL query to display the list of the city and country for
all the cities that end with letter A.
(Ans) select city,country from worldcity where city like '%a';
4. Write an SQL query to display the list of the city and country for
all the cities begins with letter M and have exactly six letters in
them.
(Ans) select city,country from worldcity where city like 'm_____';
5. Write an SQL query to display the list of the city and country for
all the cities that contain an A as the second letter.
(Ans) select city,country from worldcity where city like '_a%';
6. Write an SQL query to display the list of the city and country
for all the cities that are not in North or South America and that
do not contain six letters.
(Ans) select city,country,continent from worldcity where
continent not in('north america', 'south america') and city like
'______';
7. Write an SQL query to display the list of the city , country and
continent for all the cities in Africa, Australia and Asia.
(Ans) select city,country,continent from worldcity where
continent in('africa', 'australia', 'asia');
8. Write an SQL query to display the list of the cities and countries
that have same number of letters in the city name and the
country name.
(Ans) select city,country from worldcity where
length(city)=length(country);