# SUM and COUNT Quiz/ja

 言語: [[:{{#invoke:String|sub|SUM and COUNT Quiz/ja ``` |1 |Expression error: Unrecognized punctuation character "{". ``` }}|English]]

SUM と COUNT クイズ

bbc
name region area population gdp
Afghanistan South Asia 652225 26000000
Albania Europe 28728 3200000 6656000000
Algeria Middle East 2400000 32900000 75012000000
Andorra Europe 468 64000
...
ヨーロッパの全ての国の人口を集計する文を選べ
``` SELECT name, population FROM bbc WHERE region = 'Europe'
```
``` SELECT population FROM bbc WHERE region = 'Europe' SUM BY region
```
``` SELECT SUM(population) FROM bbc WHERE region = 'Europe'
```
``` SELECT SUM(population FROM bbc WHERE region = 'Europe')
```
``` SUM population FROM bbc WHERE region = 'Europe'
```
150000人よりも少ない人口の国の数を表示する文を選べ
``` SELECT COUNT(name) FROM bbc WHERE population < 150000
```
``` SELECT COUNT(population < 150000) FROM bbc
```
``` SELECT name FROM bbc WHERE population < 150000
```
``` SELECT population AS COUNT FROM bbc WHERE population < 150000
```
``` SELECT SUM() FROM bbc WHERE population < 150000
```
SQL の主要な集計関数のリストを選べ
AVG(), COUNT(), FIRST(), LAST(), SUM()
AVG(), COUNT(), MAX(), MEDIAN(), MIN(), ROUND(), SUM()
AVG(), COUNT(), CONCAT(), FIRST(), LAST(), MAX(), MIN(), SUM()
AVG(), COUNT(), MAX(), MIN(), SUM()
COUNT(), SUM()

``` SELECT region, SUM(area)
FROM bbc
WHERE SUM(area) > 15000000
GROUP BY region
```
 Europe 17000000
 Europe 17000000 Asia-Pacific 23460000 North America 21660000
 Europe Asia-Pacific North America
GROUP BY の用法が正しくないため結果は無し
WHERE の用法が正しくないため結果は無し
'Poland', 'Germany', 'Denmark' の人口の平均を表示するコードを選べ
``` SELECT AVG(population) FROM bbc WHERE name = ('Poland', 'Germany', 'Denmark')
```
``` SELECT AVG(population) FROM bbc WHERE name IN ('Poland', 'Germany', 'Denmark')
```
``` SELECT AVG(population) FROM bbc WHERE name LIKE ('Poland', 'Germany', 'Denmark')
```
``` SELECT AVG(population) FROM bbc WHERE name LIKE (Poland, Germany, Denmark)
```
``` SELECT population FROM bbc WHERE name IN ('Poland', 'Germany', 'Denmark')
```

``` SELECT region, AVG(population/area) AS density FROM bbc
```
``` SELECT region, COUNT(population)/COUNT(area) AS density FROM bbc GROUP BY region
```
``` SELECT region, SUM(population)/COUNT(area) AS density FROM bbc GROUP BY region
```
``` SELECT region, SUM(population)/SUM(area) AS density FROM bbc HAVING region
```
``` SELECT region, SUM(population)/SUM(area) AS density FROM bbc GROUP BY region
```

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

``` SELECT region, SUM(area)
FROM bbc
GROUP BY region
HAVING SUM(area)<= 20000000
```
 732240 13403102 17740392 4943771
 Africa 22550927 Asia-Pacific 28759578 Europe 23866987 North America 21660000
 Africa Asia-Pacific Europe North America
 Americas 732240 Middle East 13403102 South America 17740392 South Asia 9437710
 Americas Middle East South America South Asia