SQL - 예제로 배우는 sql 2

산하·2022년 4월 8일
0

SQL

목록 보기
3/9
post-thumbnail

문제 링크 바로가기 👀



👉🏻 SELECT names


1.

Q. You can use WHERE name LIKE 'B%' to find the countries that start with "B".

The % is a wild-card it can match any characters
Find the country that start with Y

A.

select name from world
where name like 'y%'

2.

Q.Find the countries that end with y

A.

select name from world
where name like '%y'

3.

Q.Luxembourg has an x - so does one other country. List them both.

Find the countries that contain the letter x

A.

select name from world
where name like '%x%'

4.

Q.Iceland, Switzerland end with land - but are there others?

Find the countries that end with land

A.

select name from world
where name like '%land'

5.

Q.Columbia starts with a C and ends with ia - there are two more like this.

Find the countries that start with C and end with ia

A.

select name from world
where name like 'c%ia'

6.

Q.Greece has a double e - who has a double o?

Find the country that has oo in the name

A.

select name from world
where name like '%oo%'

7.

Q.Bahamas has three a - who else?

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

A.

select name from world
where name like '%a%a%a%'

8.

Q.India and Angola have an n as the second character. You can use the underscore as a single character wildcard.

SELECT name FROM world
 WHERE name LIKE '_n%'
ORDER BY name

Find the countries that have "t" as the second character.

A.

select name from world
where name like '_t%'

9.

Q. Lesotho and Moldova both have two o characters separated by two other characters.

Find the countries that have two "o" characters separated by two others.

A.

select name from world
where name like '%o__o%'

10.

Q. Cuba and Togo have four characters names.

Find the countries that have exactly four characters.

A.

select name from world
where name like '____'

11.

Q. The capital of Luxembourg is Luxembourg. Show all the countries where the capital is the same as the name of the country

Find the country where the name is the capital city.

A.

select name from world
where name = capital

12.

Q. The capital of Mexico is Mexico City. Show all the countries where the capital has the country together with the word "City".

Find the country where the capital is the country plus "City".

A.

SELECT name FROM world
where capital = concat(name, ' city')

13.

Q.Find the capital and the name where the capital includes the name of the country.

A.

SELECT name, capital FROM world
WHERE capital LIKE CONCAT(name,'%')

14.

Q. Find the capital and the name where the capital is an extension of name of the country.

You should include Mexico City as it is longer than Mexico. You should not include Luxembourg as the capital is the same as the country.

A.

SELECT capital, name FROM world
WHERE capital LIKE concat(name,'%') AND capital != name 

15.

Q.For Monaco-Ville the name is Monaco and the extension is -Ville.

Show the name and the extension where the capital is an extension of name of the country.
You can use the SQL function REPLACE.

A.

SELECT name, REPLACE(capital,name,'') FROM world
WHERE capital LIKE CONCAT('%',name,'%') AND name != capital;

profile
반갑습니다 :) 백앤드 개발자 산하입니다!

0개의 댓글