SQLzoo 习题记录05-SUM and COUNT & Quiz

目录

SUM and COUNT

  1. World Country Profile: Aggregate functions
  2. Total world population
  3. List of continents
  4. GDP of Africa
  5. Count the big countries
  6. Baltic states population
  7. Using GROUP BY and HAVING
  8. Counting the countries of each continent
  9. Counting big countries in each continent
  10. Counting big continents

SUM and COUNT Quiz


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 deliver the single value 11.

namecontinentareapopulationgdp
AfghanistanAsia6522302550010020343000000
AlbaniaEurope28748283174112960000000
AlgeriaAfrica238174137100000188681000000
AndorraEurope468781153712000000
AngolaAfrica124670020609294100990000000
...

Total world population

1.

Show the total population of the world.

  • world(name, continent, area, population, gdp)
  • SELECT SUM(population)
  • FROM world;

List of continents

2.

List all the continents - just once each.

  • Select Distinct continent From world;

GDP of Africa

3.

Give the total GDP of Africa

  • Select Sum(gdp) From world
  • Where continent = 'Africa';

Count the big countries

4.

How many countries have an area of at least 1000000

  • Select Count(name) From world
  • Where area >=1000000;

Baltic states population

5.

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

  • Select Sum(population) From world
  • Where name In('Estonia', 'Latvia', 'Lithuania');

Using GROUP BY and HAVING

You may want to look at these examples: Using GROUP BY and HAVING.

Counting the countries of each continent

6.

For each continent show the continent and number of countries.

  • Select continent,count(name) as number From world
  • Group By continent;

Counting big countries in each continent

7.

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

  • Select continent,count(name) as number From world
  • Where population >= 10000000
  • Group By continent;

Counting big continents

8.

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

(Where不可用聚集函数,Having可用)

  • Select continent From world
  • Group By continent
  • Having sum(population) >= 100000000;

 

SUM and COUNT Quiz

网址:SUM and COUNT Quiz - SQLZOO

bbc
nameregionareapopulationgdp
AfghanistanSouth Asia65222526000000 
AlbaniaEurope2872832000006656000000
AlgeriaMiddle East24000003290000075012000000
AndorraEurope46864000 
...

1. Select the statement that shows the sum of population of all countries in 'Europe'

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

2. Select the statement that shows the number of countries with population smaller than 150000

  • SELECT COUNT(name) FROM bbc
  • WHERE population < 150000;

3. Select the list of core SQL aggregate functions

(Max,Min也是聚合函数)

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

4. Select the result that would be obtained from the following code:

  •  SELECT region, SUM(area)
       FROM bbc 
      WHERE SUM(area) > 15000000 
      GROUP BY region
  • No result due to invalid use of the WHERE function

5. Select the statement that shows the average population of 'Poland', 'Germany' and 'Denmark'

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

6. Select the statement that shows the medium population density of each region

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

7. Select the statement that shows the name and population density of the country with the largest population

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

8. Pick the result that would be obtained from the following code:

  •  SELECT region, SUM(area) 
       FROM bbc 
      GROUP BY region 
      HAVING SUM(area)<= 20000000

Table-D

Americas 732240 Middle East 13403102 South America 17740392 South Asia 9437710

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
no main manifest attribute, in quiz-0.0.1-SNAPSHOT.jar 是一个报错信息,表示在quiz-0.0.1-SNAPSHOT.jar包的清单文件(MANIFEST.MF)中缺少了主清单属性。 解决这个问题的方法是在pom文件中添加以下配置: ``` <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build> ``` 这个配置会在打包过程中自动生成并添加主清单属性,确保jar包能够正确运行。 同时,需要确保MANIFEST.MF文件夹和MANIFEST.MF文件位于项目的根目录下,才能够在本地使用java -jar命令运行jar包或在Docker容器中启动。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* [no main manifest attribute, in app-1.0-SNAPSHOT.jar](https://blog.csdn.net/YonJarLuo/article/details/128530264)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 33.333333333333336%"] - *2* [no main manifest attribute, in schoolspringboot-0.0.1-SNAPSHOT.jar](https://blog.csdn.net/weixin_52236586/article/details/131679246)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 33.333333333333336%"] - *3* [start-0.0.1-SNAPSHOT.jar](https://download.csdn.net/download/qq_38807606/12268407)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 33.333333333333336%"] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值