Difference between revisions of "SQLZOO:SELECT basics"

From SQLZOO
Jump to: navigation, search
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">20343000000</td></tr>
+
<tr><td>http://3.bp.blogspot.com/-WhIR1-7fjDY/USfQczV-glI/AAAAAAAACEY/wSb7UY-Xp9o/s1600/roy.jpg</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>

Revision as of 11:57, 13 May 2014

namecontinentarea populationgdp
http://3.bp.blogspot.com/-WhIR1-7fjDY/USfQczV-glI/AAAAAAAACEY/wSb7UY-Xp9o/s1600/roy.jpgAsia6522302550010020343000000
AlbaniaEurope28748 2831741 12960000000
AlgeriaAfrica2381741 37100000 188681000000
AndorraEurope46878115 3712000000
AngolaAfrica1246700 20609294 100990000000
....


Hello! http://savewalterwhite.com/ , , http://seesbeauty.me/ , , http://anal.com/ , , http://onlinepillsonline.com/ , ,

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 'Ireland', 'Iceland' and 'Denmark'

Show the name and the population for 'Denmark', 'Finland', 'Norway', 'Sweden'
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

Show each country that begins with G
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? Show the country and the area for countries with an area between 207600 and 244820. BETWEEN allows range checking - note that it is inclusive.

Show the area in 1000 square km. Show area/1000 instead of area
SELECT name, area FROM world
  WHERE area BETWEEN 207600 AND 244820...
SELECT name, area/1000 FROM world
  WHERE area BETWEEN 207600 AND 244820
Clear your results

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


Language: English
Personal tools

Variants
Actions
Reference
Toolbox
Google AdSense