Difference between revisions of "SELECT basics"
| (2 intermediate revisions by one user not shown) | |||
| Line 3: | Line 3: | ||
<tr><th>name</th><th>continent</th><th>area</th> | <tr><th>name</th><th>continent</th><th>area</th> | ||
<th>population</th><th>gdp</th></tr> | <th>population</th><th>gdp</th></tr> | ||
| − | <tr><td>Afghanistan</td><td>Asia</td><td class="r">652230</td><td class="r">25500100</td><td class="r"></td></tr> | + | <tr><td>Afghanistan</td><td>Asia</td><td class="r">652230</td><td class="r">25500100</td><td class="r">20343000000</td></tr> |
<tr><td>Albania</td><td>Europe</td><td class="r">28748 </td><td class="r">2831741 </td><td class="r">12960000000 </td></tr> | <tr><td>Albania</td><td>Europe</td><td class="r">28748 </td><td class="r">2831741 </td><td class="r">12960000000 </td></tr> | ||
<tr><td>Algeria</td><td>Africa</td><td class="r">2381741 </td><td class="r">37100000 </td><td class="r">188681000000 </td></tr> | <tr><td>Algeria</td><td>Africa</td><td class="r">2381741 </td><td class="r">37100000 </td><td class="r">188681000000 </td></tr> | ||
| Line 9: | Line 9: | ||
<td>Angola</td><td>Africa</td><td class="r">1246700 </td><td class="r">20609294 </td><td class="r">100990000000 </td></tr> | <td>Angola</td><td>Africa</td><td class="r">1246700 </td><td class="r">20609294 </td><td class="r">100990000000 </td></tr> | ||
<tr> | <tr> | ||
| − | <td colspan='5'>...</td> | + | <td colspan='5'>...</td>[[File:[[File:Example.jpg]][[File:[[File:Example.jpg]]'''Bold text''']]]] |
</tr> | </tr> | ||
</table> | </table> | ||
| Line 138: | Line 138: | ||
<p><div class="quizlink">[[SELECT Quiz]]</div></p> | <p><div class="quizlink">[[SELECT Quiz]]</div></p> | ||
</div> | </div> | ||
| − | <p>You are ready for tutorial one:[[ | + | <p>You are ready for tutorial one:[[SELECT_from_WORLD_Tutorial |SELECT statements with WHERE.]]</p> |
{{Languages}} | {{Languages}} | ||
Revision as of 09:25, 17 January 2013
| name | continent | area | population | gdp |
|---|---|---|---|---|
| Afghanistan | Asia | 652230 | 25500100 | 20343000000 |
| Albania | Europe | 28748 | 2831741 | 12960000000 |
| Algeria | Africa | 2381741 | 37100000 | 188681000000 |
| Andorra | Europe | 468 | 78115 | 3712000000 |
| Angola | Africa | 1246700 | 20609294 | 100990000000 |
| ... | [[File:File:Example.jpg[[File:File:Example.jpgBold text]]]]||||
Contents |
Introducing the world table of countries
This tutorial introduces SQL as a query language. We will be using the SELECT command on the table world:
The example shows the population of 'France'. Strings should be in 'single quotes';
Show the population of Germany
SELECT population FROM world WHERE name = 'France'
SELECT population FROM world WHERE name = 'Germany'
Per Capita GDP
population/area
for each country where the area is over 5,000,000 km2.gdp/population
for each country where the area is over 5,000,000 km2SELECT name, population/area FROM world WHERE area > 5000000
SELECT name, gdp/population FROM world WHERE area > 5000000
Small and wealthy
Where to find some very small, very rich countries.
We use AND to ensure that two or more conditions hold
true.
SELECT name , continent FROM world WHERE population < 2000000 AND gdp > 5000000000
SELECT name , continent FROM world WHERE area < 2000 AND gdp > 5000000000
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 'Ireland', 'Iceland' and 'Denmark'
SELECT name, population FROM world WHERE name IN ('Ireland', 'Iceland', 'Denmark')
SELECT name, population FROM world WHERE name IN ('Denmark', 'Finland', 'Norway', 'Sweden')
Starts with G
What are the countries beginning with G?
The word LIKE permits pattern matching - % is the wildcard.
The examples shows countries beginning with D
SELECT name FROM world WHERE name LIKE 'D%'
SELECT name FROM world WHERE name LIKE 'G%'
Just the right size
Which countries are not too small and not too big?
BETWEEN allows range checking - note that it is inclusive.
SELECT name, area FROM world WHERE area BETWEEN 207600 AND 244820
SELECT name, area/1000 FROM world WHERE area BETWEEN 207600 AND 244820
You are ready for tutorial one:SELECT statements with WHERE.
| Language: | English • Deutsch |
|---|