SQL - 예제로 배우는 SQL 5

산하·2022년 5월 17일
0

SQL

목록 보기
6/9
post-thumbnail

문제 링크 바로가기 👀



👉🏻 SELECT from WORLD Tutorial


1. Bigger than Russia

Q. List each country name where the population is larger than that of 'Russia'.

A.

SELECT name FROM world
  WHERE population >
     (SELECT population FROM world
      WHERE name='Russia')

2. Richer than UK

Q.Show the countries in Europe with a per capita GDP greater than 'United Kingdom'.

A.

SELECT name FROM world
  WHERE continent = 'Europe'
  AND gdp/population > 
    (SELECT gdp/population FROM world
     WHERE name = 'United Kingdom') 

3. Neighbours of Argentina and Australia

Q. List the name and continent of countries in the continents containing either Argentina or Australia. Order by name of the country.

A.

SELECT name, continent FROM world 
  WHERE continent IN 
    (SELECT continent FROM world WHERE name IN ('Argentina','Australia')) 
      ORDER BY name

4. Between Canada and Poland

Q. Which country has a population that is more than United Kingom but less than Germany? Show the name and the population

A.

SELECT name, population FROM world
  WHERE population >
    (SELECT population FROM world WHERE name = 'United Kingdom')
  AND population <
    (SELECT population FROM world WHERE name = 'Germany')

5. Percentages of Germany

Q. Germany (population 80 million) has the largest population of the countries in Europe. Austria (population 8.5 million) has 11% of the population of Germany.

Show the name and the population of each country in Europe. Show the population as a percentage of the population of Germany.

The format should be Name, Percentage for example:

namepercentage
Albania3%
Andorra0%
Austria11%

... ...

A.

SELECT name , CONCAT(ROUND((population*100)/(SELECT population FROM world WHERE name = 'Germany'),0),'%') FROM world
WHERE continent = 'Europe' 

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

0개의 댓글