import sqlite3 # Bibliothek für SQLite (in Python-Standard vorhanden)

con = sqlite3.connect("terra.sqlite")

cursor = con.cursor()

print("Erste Version: ")
SQLBefehl = """
  SELECT ort.Name, ort.Einwohner, kontinent.Name AS Kontinentname 
    FROM ort, land, kontinent 
   WHERE ort.LNR  = land.LNR 
     AND land.KNR = kontinent.KNR
"""                

cursor.execute(SQLBefehl)

# Durchlaufen der Ergebnisse
row = cursor.fetchone()
while row != None:
  if row[1]>1000000 and row[2]=='Europa':
     print("%s (%d)" % (row[0],row[1]) )
  row = cursor.fetchone()


print("---------------")
print("---------------")
print("Zweite Version: ")
SQLBefehl = """
  SELECT ort.Name, ort.Einwohner 
    FROM ort, land, kontinent 
   WHERE ort.LNR  = land.LNR 
     AND land.KNR = kontinent.KNR 
     AND ort.Einwohner > 1000000 
     AND kontinent.Name = 'Europa'
"""

cursor.execute(SQLBefehl)

row = cursor.fetchone()
while row != None:
  print("%s (%d)" % (row[0],row[1]) )
  row = cursor.fetchone()

cursor.close()


