SQL - 예제로 배우는 SQL 6

산하·2022년 5월 17일
0

SQL

목록 보기
7/9
post-thumbnail

문제 링크 바로가기 👀



👉🏻 SUM and COUNT


1. Total world population

Q. Show the total population of the world.

world(name, continent, area, population, gdp)

A.

SELECT SUM(population) FROM world

2. List of continents

Q. List all the continents - just once each.

A.

SELECT DISTINCT(continent) FROM world

3. GDP of Africa

Q. Give the total GDP of Africa

A.

SELECT SUM(gdp) FROM world
WHERE continent = 'Africa'

4. Count the big countries

Q. How many countries have an area of at least 1000000

A.

SELECT COUNT(name) FROM world
WHERE area > 1000000

5. Baltic states population

Q. What is the total population of ('Estonia', 'Latvia', 'Lithuania')

A.

SELECT SUM(population) FROM world
WHERE name IN  ('Estonia', 'Latvia', 'Lithuania')

6. Counting the countries of each continent

Q. For each continent show the continent and number of countries.

A.

SELECT continent, COUNT(name) FROM world 
GROUP BY continent

7. Counting big countries in each continent

Q. For each continent show the continent and number of countries with populations of at least 10 million.

A.

SELECT continent,COUNT(name) FROM world
WHERE population > 10000000
GROUP BY continent

8. Counting big continents

Q. List the continents that have a total population of at least 100 million.

A.

SELECT continent FROM world
GROUP BY continent
HAVING 100000000 < SUM(population)
profile
반갑습니다 :) 백앤드 개발자 산하입니다!

0개의 댓글