1. 程式人生 > >sqlzoo答案參考

sqlzoo答案參考

select basics

1.Modify it to show the population of Germany

select population
from world
where name='Germany'

2.show the name and the population for 'Sweden', 'Norway' and 'Denmark'.

select name, population 
from world
where name in ('Sweden', 'Norway', 'Denmark')

3.Modify it to show the country and the area for countries with an area between 200,000 and 250,000.

select name,area
from world
where area between 200000 and 250000

select from world

1、Observe the result of running this SQL command to show the name, continent and population of all countries.

select name, continent, population 
from world

2. Show the name for the countries that have a population of at least 200 million. 200 million is 200000000, there are eight zeros.

select name 
from world
where population >= 200000000

3. Give the name and the per capita GDP for those countries with a population of at least 200 million.

select name,gdp/population
from world
where population>=200000000

4. Show the name and population in millions for the countries of the continent 'South America'. Divide the population by 1000000 to get population in millions.

select name,population/1000000
from world
where continent='South America'

5. Show the name and population for France, Germany, Italy

select name,population
from world
where name in ('France','Germany','Italy')

6. Show the countries which have a name that includes the word 'United'

select name
from world
where name like ('%United%')

7. Two ways to be big: A country is big if it has an area of more than 3 million sq km or it has a population of more than 250 million.

Show the countries that are big by area or big by population. Show name, population and area.

select name,population,area
from world
where area>3000000 or population>250000000

8. Exclusive OR (XOR). Show the countries that are big by area or big by population but not both. Show name, population and area.

Australia has a big area but a small population, it should be included.

Indonesia has a big population but a small area, it should be included.

China has a big population and big area, it should be excluded.

United Kingdom has a small population and a small area, it should be excluded.

select name,population,area
from world
where (population>250000000 or area>3000000) 
and not (population>250000000 and area>3000000)

9. Show the name and population in millions and the GDP in billions for the countries of the continent 'South America'. Use the ROUND function to show the values to two decimal places.

For South America show population in millions and GDP in billions both to 2 decimal places.

select name,round(population/1000000,2),round(gdp/1000000000,2)
from world
where continent='South America'

10. Show the name and per-capita GDP for those countries with a GDP of at least one trillion (1000000000000; that is 12 zeros). Round this value to the nearest 1000.

Show per-capita GDP for the trillion dollar countries to the nearest $1000.

select name,round(gdp/population,-3)
from world
where gdp>=1000000000000

11. Greece has capital Athens.

Each of the strings 'Greece', and 'Athens' has 6 characters.

Show the name and capital where the name and the capital have the same number of characters.

You can use the LENGTH function to find the number of characters in a string

select name,capital
from world
where length(name)=length(capital)

12. The capital of Sweden is Stockholm. Both words start with the letter 'S'.

Show the name and the capital where the first letters of each match. Don't include countries where the name and the capital are the same word.

select name,capital
from world
where left(name,1)=left(capital,1) and name<>capital

13. Equatorial Guinea and Dominican Republic have all of the vowels (a e i o u) in the name. They don't count because they have more than one word in the name.

Find the country that has all the vowels and no spaces in its name.

You can use the phrase name NOT LIKE '%a%' to exclude characters from your results.

The query shown misses countries like Bahamas and Belarus because they contain at least one 'a'

select name
from world
where name not like '% %' and name like '%a%' and name like '%o%'
and name like '%e%' and name like '%i%' and name like '%u%'

SELECT from Nobel Tutorial

  1. Change the query shown so that it displays Nobel prizes for 1950.
select yr, subject, winner
from nobel
where yr = 1950

2. Show who won the 1962 prize for Literature.

select winner
from nobel
where yr=1962 and subject='Literature'

3. Show the year and subject that won 'Albert Einstein' his prize.

select yr,subject
from nobel
where winner='Albert Einstein'

4. Give the name of the 'Peace' winners since the year 2000, including 2000.

select winner
from nobel
where yr>=2000 and subject='Peace'

5. Show all details (yr, subject, winner) of the Literature prize winners for 1980 to 1989 inclusive.

select yr,subject,winner
from nobel
where yr between 1980 and 1989 and subject='Literature'

6. Show all details of the presidential winners: Theodore Roosevelt, Woodrow Wilson, Jimmy Carter, Barack Obama

select * 
from nobel
where winner in ('Theodore Roosevelt','Woodrow Wilson','Jimmy Carter','Barack Obama')

7. Show the winners with first name John

select winner
from nobel
where winner like 'John %'

8. Show the year, subject, and name of Physics winners for 1980 together with the Chemistry winners for 1984.

select yr,subject,winner
from nobel
where (yr=1984 and subject='Chemistry') or (yr=1980 and subject='Physics')

9. Show the year, subject, and name of winners for 1980 excluding Chemistry and Medicine

select yr,subject,winner
from nobel
where yr=1980 and (subject<>'Chemistry' and subject<>'Medicine')

10. Show year, subject, and name of people who won a 'Medicine' prize in an early year (before 1910, not including 1910) together with winners of a 'Literature' prize in a later year (after 2004, including 2004)

select yr,subject,winner
from nobel
where (subject='Medicine' and yr<1910) or (subject='Literature' and yr>=2004)

11. Find all details of the prize won by PETER GRÜNBERG

select *
from nobel
where winner like 'peter gr%nberg'

12. Find all details of the prize won by EUGENE O'NEILL

SELECT *
FROM nobel
WHERE winner = 'Eugene O''Neill'

13. List the winners, year and subject where the winner starts with Sir. Show the the most recent first, then by name order.

select winner,yr,subject
from nobel
where winner like 'sir%' order by yr desc,winner

14. Show the 1984 winners and subject ordered by subject and winner name; but list Chemistry and Physics last.

The expression subject IN ('Chemistry','Physics') can be used as a value

- it will be 0 or 1.

select winner, subject
from nobel
where yr=1984
order by subject in ('Chemistry','Physics'),subject,winner

SELECT within SELECT Tutorial

  1. List each country name where the population is larger than that of 'Russia'.
select name
from world
where population>(select population 
                  from world
                  where name='Russia')

2. Show the countries in Europe with a per capita GDP greater than 'United Kingdom'.

select name
from world
where continent='Europe' and gdp/population>(select gdp/population
                                             from world
                                             where name='United Kingdom')

3. List the name and continent of countries in the continents containing either Argentina or Australia. Order by name of the country.

select name,continent
from world
where continent in (select continent from world
                    where name in ('Argentina','Australia')) order by name

4. Which country has a population that is more than Canada but less than Poland? Show the name and the population.

select name,population
from world
where population>(select population from world where name='Canada')
  and population<(select population from world where name ='Poland')

5. Show the name and the population of each country in Europe. Show the population as a percentage of the population of Germany.

select name,
concat(round(population/(select population from world where name='Germany')*100),'%')
from world
where continent='Europe'

注:上面的concat(region,name)將region和name沾合在一起顯示

6. Which countries have a GDP greater than every country in Europe? [Give the name only.] (Some countries may have NULL gdp values)

select name
from world
where gdp>all(select gdp from world where continent='Europe' and gdp>0)

7. Find the largest country (by area) in each continent, show thecontinent, the name and the area:

select continent,name,area
from world as x
where x.area=(select max(y.area)
              from world as y
              where x.continent=y.continent)

注:x,y表示用到了2次world表

8. List each continent and the name of the country that comes first alphabetically.

select continent,name
from world x
where x.name<=all(select name from world y where x.continent=y.continent)
order by name  

9. Find the continents where all countries have a population <= 25000000. Then find the names of the countries associated with these continents. Show name, continent and population.

select name,continent,population
from world as x
where 25000000>=all
(select population from world y where x.continent=y.continent)

10. Some countries have populations more than three times that of any of their neighbours (in the same continent). Give the countries and continents.

select name,continent
from world as x
where population/3>=all(select population from world y where 
 x.continent=y.continent and x.name!=y.name)

SUM and COUNT

  1. Show the total population of the world.
select sum(population)
from world

2.List all the continents - just once each.

select distinct continent
from world

3. Give the total GDP of Africa

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

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

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

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

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

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

select continent,count(name)
from world
group by continent having count(name)

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

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

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

select continent
from world
group by continent having sum(population)>=100000000

The JOIN operation

  1. Modify it to show the matchid and player name for all goals scored by Germany. To identify German players, check for: teamid = 'GER'
select matchid,player
from goal
where teamid='GER'

2. Show id, stadium, team1, team2 for just game 1012

select id,stadium,team1,team2
from game
where id=1012

3. Modify it to show the player, teamid, stadium and mdate for every German goal.

select player,teamid,stadium,mdate
from goal,game
where goal.matchid=game.id and teamid='GER'

4.Show the team1, team2 and player for every goal scored by a player called Mario player LIKE 'Mario%'

select team1,team2,player
from game,goal
where game.id=goal.matchid and player like 'Mario%'

5.Show player, teamid, coach, gtime for all goals scored in the first 10 minutes gtime<=10

select player,teamid,coach,gtime
from goal,eteam
where eteam.id=goal.teamid and gtime<=10

6.List the the dates of the matches and the name of the team in which 'Fernando Santos' was the team1 coach.

            
           

相關推薦

sqlzoo答案參考

select basics1.Modify it to show the population of Germanyselect population from world where name='Germany' 2.show the name and the popula

C++ PRimer PLUS(第六版)中文版 第十一章chapter11答案 參考

bject get quit primer rime 答案 std cat tar #include <iostream>#include <cstdlib>#include <ctime>#include "vector.h" int

sqlzoo 答案全集

sqlzoo官網 SELECT basics 答案 SELECT from world 答案 SELECT from nobel 答案 todo SELECT in SELECT 答案 todo SUM and COUNT 答案 JOIN 答案

我的譚浩強版《c++程式設計》習題答案參考(新近新增第六章指標,將繼續)

        我正在學習譚浩強的《c++程式設計》,這是我所學到的章節所做的習題,希望能記錄下程式設計學習的進步過程。每做完一章的練習,就把它們放上網。                                                     《c++程式設計

python編程快速上手之第10章實踐項目參考答案(11.11.2)

答案 nic .com final timeout pre image 保存圖片 iframe #!/usr/bin/env python # -*- coding:utf-8 -*- import os import re import urllib import

python編程快速上手之第10章實踐項目參考答案(11.11.3)

name driver ret text rul from url .get right from selenium import webdriver from selenium.webdriver.common.keys import Keys import time

python編程快速上手之第10章實踐項目參考答案(12.13.1)

true style span tip 12.1 user python input multi #! python3 # multiplicationTable.py import openpyxl,os from openpyxl.styles import Font

python編程快速上手之第13章實踐項目參考答案(13.6.1)

encrypted iter close ffi mes python編程 實踐項目 reader blog import os,PyPDF2 os.chdir(‘D:\\My Documents‘) for folderName, subfolders, filenam

python編程快速上手之第13章實踐項目參考答案(13.6.2)

nbsp python add sha odi log span import imp #! python3 # encoding: UTF-8 import os import docx from docx import Document from docx.shar

python編程快速上手之第15章實踐項目參考答案(17.7.2)

col ges code sid documents mod 編程 bsp tof #! python3 # Import modules and write comments to describe this program. import zipfile, os fr

python編程快速上手之第15章實踐項目參考答案(17.7.3)

lane width ima font height 開始 users nco window #! python3 # encoding: UTF-8 import os,docx from PIL import Image, ImageDraw from PIL imp

sqlzoo練習答案--SELECT names/zh

bsp rep ges clas otto 全部 replace capi 包含 namecontinentAfghanistanAsiaAlbaniaEuropeAlgeriaAfricaAndorraEuropeAngolaAfrica....name:國家名稱con

SQLZOO網頁中SQL的答案

開頭 and title with div asc asi trie ont SELECT from world篇 11. 題目: The CASE statement shown is used to substitute North America forCa

MySQL練習題參考答案

primary ref local ble cap == arc score host 導出現有數據庫數據: mysqldump -u用戶名 -p密碼 數據庫名稱 >導出文件路徑 # 結構+數據 mysqldump -u用戶名 -p密碼 -d 數

sqlzoo練習答案--SELECT within SELECT Tutorial

count lan call ase decimal data- mono rgb same This tutorial looks at how we can use SELECT statements within SELECT statements to perf

《機器學習》 --周誌華版(西瓜書)--課後參考答案

snoopy 實踐 評估 ref 得到 clas tle car 分析 《機器學習》 --周誌華版(西瓜書)--課後參考答案 對機器學習一直很感興趣,也曾閱讀過李航老師的《統計學習導論》和Springer的《統計學習導論-基於R應用》等相關書籍,但總感覺自己缺乏深入

馬哥iptables作業參考答案

iptables練習:INPUT和OUTPUT默認策略為DROP; 1、限制本地主機的web服務器在周一不允許訪問;新請求的速率不能超過100個每秒;web服務器包含了admin字符串的頁面不允許訪問;web服務器僅允許響應報文離開本機; 在你想加入的表上鏈上 直接加上 -m time --weekday

【視覺SLAM14講】ch4心得與課後題答案【僅供參考

參考 http sim 數學推導 數學 之間 沒有 sla per 學習心得: 在研究SLAM時候,除了對三維世界剛體運動表示外(ch3),由於噪聲的影響,還要進行對可能的位姿進行優化,而旋轉矩陣必須得是行列式為1的正交矩陣, 為了減少這種約束,我們希望通過李群和李代數

寶雞市第二次質量檢測高三數學文科、理科參考答案

參考 down wan blog clas mark pos 數學 HR 寶雞市第二次質量檢測高三數學文科參考答案 文科 寶雞市第二次質量檢測高三數學理科參考答案 理科 寶雞市第二次質量檢測高三數學文科、理科參考答案

Java面試題收集以及參考答案(100道)

str 單元 特殊的表 常見 文件的 邏輯判斷 浮點 類與對象 integer 不積跬步無以至千裏,這裏會不斷收集和更新Java基礎相關的面試題,目前已收集100題。 1.什麽是B/S架構?什麽是C/S架構 B/S(Browser/Server),瀏覽器/服務器程序