Difference between revisions of "SELECT basics/zh"

From SQLZOO
Jump to: navigation, search
(Introducing the world table of countries)
(Introducing the world table of countries)
Line 26: Line 26:
 
</source>
 
</source>
 
</div>
 
</div>
 +
 +
 +
==Per Capita GDP==
 +
<div class='qu'>
 +
<div>查詢顯示面積為 5,000,000 以上平方公里的國家,該國家的人口密度(<code>population/area</code>)。人口密度並不是 WORLD 表格中的欄,但我們可用公式(<code>population/area</code>)計算出來。
 +
 +
<div class='imper'>修改此例子,查詢面積為 5,000,000 以上平方公里的國家,對每個國家顯示她的名字和人均國內生產總值(<code>population/area</code>)。
 +
</div>
 +
<source lang='sql' class='def'>
 +
SELECT name, population/area FROM world
 +
  WHERE area > 5000000
 +
</source>
 +
 +
<source lang='sql' class='ans'>
 +
SELECT name, gdp/population FROM world
 +
  WHERE area > '5000000'
 +
</source>
 +
 +
</div>
 +
 +
==Scandinavia==
 +
<div class='qu'>
 +
Checking a list The word <b>IN</b> allows us to check if an item is in a list.
 +
The example shows the name and population for the countries 'Luxembourg', 'Mauritius' and 'Samoa'.
 +
<div class='imper'>Show the '''name''' and the '''population''' for 'Ireland', 'Iceland' and 'Denmark'.</div>
 +
 +
 +
<source lang='sql' class='def'>
 +
SELECT name, population FROM world
 +
  WHERE name IN ('Luxembourg', 'Mauritius', 'Samoa');
 +
</source>
 +
 +
<source lang='sql' class='ans'>
 +
SELECT name, population FROM world
 +
  WHERE name IN ('Ireland', 'Iceland', 'Denmark');
 +
</source>
 +
</div>
 +
 +
<div> 
 +
<p><div class="quizlink">[[SELECT Quiz]]</div></p>
 +
</div>
 +
 +
<div class='quizlink'>[http://socweb8.napier.ac.uk/~40052114/regex/index.php?title=How_To_Play Try the regular expressions game.]</div>
 +
 +
<p>You are ready for tutorial one:[[SELECT_from_WORLD_Tutorial |SELECT statements with WHERE.]]</p>
 +
 +
 +
 +
==Just the right size==
 +
<div class='qu'>
 +
Which countries are not too small and not too big?
 +
<code>BETWEEN</code> allows range checking (range specified is inclusive of boundary values). The example below shows countries with an area of 250,000-300,000 sq. km. Modify it to show the country and the area for countries with an area between 200,000 and 250,000.
 +
 +
<source lang='sql' class='def'>
 +
SELECT name, area FROM world
 +
  WHERE area BETWEEN 250000 AND 300000
 +
</source>
 +
 +
 +
<source lang='sql' class='ans'>
 +
SELECT name, area FROM world
 +
  WHERE area BETWEEN 200000 AND 250000
 +
</source>
 +
 +
</div>
 +
 +
 +
<p>You are ready for tutorial one:[[SELECT_from_WORLD_Tutorial |SELECT statements with WHERE.]]</p>
 +
 +
 +
{{Languages}}
  
 
==Per Capita GDP==
 
==Per Capita GDP==

Revision as of 13:55, 5 January 2016

Introducing the world table of countries

這個教程介紹SQL語言。我們會使用SELECT語句。on the table France:

Summary

這個例子顯示’France法國’的人口。字串應該在'單引號'中。

修改此例子,以顯示德國 Germany 的人口。

SELECT population FROM world
  WHERE name = 'France'
SELECT population FROM world
  WHERE name = 'Germany'


Per Capita GDP

查詢顯示面積為 5,000,000 以上平方公里的國家,該國家的人口密度(population/area)。人口密度並不是 WORLD 表格中的欄,但我們可用公式(population/area)計算出來。
修改此例子,查詢面積為 5,000,000 以上平方公里的國家,對每個國家顯示她的名字和人均國內生產總值(population/area)。
SELECT name, population/area FROM world
  WHERE area > 5000000
SELECT name, gdp/population FROM world
  WHERE area > '5000000'

Scandinavia

Checking a list The word IN allows us to check if an item is in a list. The example shows the name and population for the countries 'Luxembourg', 'Mauritius' and 'Samoa'.

Show the name and the population for 'Ireland', 'Iceland' and 'Denmark'.


SELECT name, population FROM world
  WHERE name IN ('Luxembourg', 'Mauritius', 'Samoa');
SELECT name, population FROM world
  WHERE name IN ('Ireland', 'Iceland', 'Denmark');

You are ready for tutorial one:SELECT statements with WHERE.


Just the right size

Which countries are not too small and not too big? BETWEEN allows range checking (range specified is inclusive of boundary values). The example below shows countries with an area of 250,000-300,000 sq. km. 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 250000 AND 300000


SELECT name, area FROM world
  WHERE area BETWEEN 200000 AND 250000


You are ready for tutorial one:SELECT statements with WHERE.


Language:Project:Language policy English  • Deutsch • 日本語 • 中文

Per Capita GDP

查詢顯示面積為 5,000,000 以上平方公里的國家,該國家的人口密度(population/area)。人口密度並不是 WORLD 表格中的欄,但我們可用公式(population/area)計算出來。
修改此例子,查詢面積為 5,000,000 以上平方公里的國家,對每個國家顯示她的名字和人均國內生產總值(population/area)。
SELECT name, population/area FROM world
  WHERE area > 5000000
SELECT name, gdp/population FROM world
  WHERE area > '5000000'