융무의 기술블로그
article thumbnail
Published 2020. 7. 2. 20:37
[SQL][sqlzoo] SUM and COUNT Algorithm/SQL

SUM and COUNT                                                                                                       

 

SUM and COUNT - SQLZOO

World Country Profile: Aggregate functions This tutorial is about aggregate functions such as COUNT, SUM and AVG. An aggregate function takes many values and delivers just one value. For example the function SUM would aggregate the values 2, 4 and 5 to del

sqlzoo.net

1.Total world population

SELECT SUM(population)
FROM world

2.List of continents

select distinct continent
from world

3.GDP of Africa

select sum(gdp) 
from world 
where continent ='africa'

4.Count the big countries

select count(name) 
from world 
where area>=1000000

5.Baltic states population

select sum(population) 
from world 
where name in('Estonia', 'Latvia', 'Lithuania')

6.Counting the countries of each continent

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

7.Counting big countries in each continent

select continent,count(population) 
from world 
where population >=10000000 
group by continent

 

8.Counting big continents

SELECT continent 
FROM world 
GROUP BY continent 
HAVING SUM(population) >= 100000000

SUM and COUNT Quiz                                                                                              

1.

 SELECT SUM(population) FROM bbc WHERE region = 'Europe'

2.

 SELECT COUNT(name) FROM bbc WHERE population < 150000

3.

AVG(), COUNT(), MAX(), MIN(), SUM()

4.

No result due to invalid use of the WHERE function

5.

 SELECT AVG(population) FROM bbc WHERE name IN ('Poland', 'Germany', 'Denmark')

6.

 SELECT region, SUM(population)/SUM(area) AS density FROM bbc GROUP BY region

7.

SELECT name, population/area AS density FROM bbc WHERE population = (SELECT MAX(population) FROM bbc)

8.

Table-D

Americas 732240
Middle East 13403102
South America 17740392
South Asia 9437710

 

'Algorithm > SQL' 카테고리의 다른 글

[SQL][sqlzoo] More JOIN operations  (0) 2020.07.02
[SQL][sqlzoo] The JOIN operation  (0) 2020.07.02
[SQL][sqlzoo] SELECT within SELECT  (2) 2020.07.02
[SQL][sqlzoo] SELECT from Nobel  (0) 2020.07.02
[SQL][sqlzoo] SELECT from world  (0) 2020.07.02
profile

융무의 기술블로그

@융무

포스팅이 좋았다면 "좋아요❤️" 또는 "구독👍🏻" 해주세요!