SELECT basics/de
Jump to navigation
Jump to search
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 | |
... |
Einführung in die Arbeit mit der Tabelle der BBC-Länderprofile
Dieses Tutorium stellt SQL als Abfragesprache vor. Die SELECT-Anweisung wird am Beispiel der Tabelle bbc demonstriert:
Zusammenfassung
Das Beispiel zeigt die Bevölkerungszahl von Frankreich ('France'). Zeichenketten (Strings) sind mit 'einfachem Hochkomma' anzugeben.
Zeige die Bevölkerungszahl von Deutschland ('Germany').
SELECT population FROM bbc
WHERE name = 'France'
SELECT population FROM bbc
WHERE name = 'Germany'
Diese Abfrage zeigt die Bevölkerungsdichte (
population/area
) jedes Landes mit einer Fläche größer als 5.000.000 km2.Zeige das Pro-Kopf-Einkommen (
gdp/population
) für jedes Land mit einer Fläche größer als 5.000.000 km2.SELECT name, population/area FROM bbc
WHERE area > 5000000
SELECT name, gdp/population FROM bbc
WHERE area > 5000000
Welche Länder sind sehr klein, aber auch sehr reich?
Wir verwenden
Wir verwenden
AND
um sicherzustellen, dass nur dann ein Ergebnis geliefert wird, wenn alle (Teil-)Bedingungen wahr sind.Das Beispiel zeigt die Länder mit geringer Bevölkerungszahl und hohem Bruttoinlandsprodukt (GDP).
Zeige die Namen (
name
) und Regionen (region
) der Länder mit einer Fläche (area
) kleiner 2.000 km2 und einem Bruttoinlandsprodukt größer als 5 Milliarden (= 5.000.000.000).SELECT name, region
FROM bbc
WHERE population < 2000000
AND gdp > 5000000000
SELECT name , region
FROM bbc
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'
Show the name and the population for 'Denmark', 'Finland', 'Norway', 'Sweden'
SELECT name, population FROM bbc
WHERE name IN ('Ireland', 'Iceland',
'Denmark')
SELECT name, population FROM bbc
WHERE name IN ('Denmark', 'Finland',
'Norway', 'Sweden')
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 bbc
WHERE name LIKE 'D%'
SELECT name FROM bbc
WHERE name LIKE 'G%'
Which countries are not too small and not too big?
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 bbc
WHERE area BETWEEN 207600 AND 244820
SELECT name, area/1000 FROM bbc
WHERE area BETWEEN 207600 AND 244820
Clear your results
You are ready for tutorial one:SELECT statements with WHERE.
Language: | [[:{{#invoke:String|sub|SELECT basics/de
|1 |Expression error: Unrecognized punctuation character "{".}}|English]] |
---|