日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > 数据库 >内容正文

数据库

SQLZOO刷题记录5——SUM and COUNT

發布時間:2024/1/18 数据库 43 豆豆
生活随笔 收集整理的這篇文章主要介紹了 SQLZOO刷题记录5——SUM and COUNT 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

World Country Profile: Aggregate functions(世界國家概況:綜合功能)

題目7:Counting big countries in each continent

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

(對于每個大洲,顯示大洲和人口數量超過10000萬的國家數量)

解題7:

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

題目8:Counting big continents

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

(列出大洲,大洲的總人口數至少是100000萬)

解題8:

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

注意:對比題目7和題目8,WHERE,GROUP BY 與 GROUP BY , HAVING 的關系。前者在分組之前進行篩選,后者在分組后進行篩選。

測試 SUM and COUNT Quiz

3. Select the list of core SQL aggregate functions(sql中的聚集函數)

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

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

?解題5:SELECT AVG(population) FROM bbc WHERE name IN ('Poland', 'Germany', 'Denmark')

注意:SQL 中等于 后面是某一個特定值,而IN 后面可以是一個結果集。如果結果集只有一個值時“=”等價于“IN” ,如果結果集有多個值時,IN 等價于 多個 “=”或。

col = 'A' 等價于 col IN ('A')
col = 'A' or col ='B' or col ='C' 等價于 IN('A','B','C')

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)

The nobel table can be used to practice more SUM and COUNT functions.

題目9:Show the years in which three prizes were given for Physics.

nobel(yr, subject, winner)

解題9:

SELECT yr FROM nobel WHERE subject = 'Physics' GROUP BY yr HAVING COUNT(winner) = 3

注意:根據題意的理解,確定WHERE ,GROUP BY 和 HAVING 中各自對應什么條件。

題目12:GROUP BY yr, subject

Show the year and subject where 3 prizes were given. Show only years 2000 onwards.

顯示頒發3個獎項的年份和主題。只顯示2000年及以后。

nobel(yr, subject, winner)

解題12:

SELECT yr, subject FROM nobel WHERE yr >= 2000 GROUP BY yr, subject HAVING COUNT(subject) = 3

總結

以上是生活随笔為你收集整理的SQLZOO刷题记录5——SUM and COUNT的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。