Database Lab: SQL Exercises
SQL-Aufgaben / SQL Exercises
This document lists the SQL exercises. Each exercise has additional information:
- hint: for many queries, a hint is provided. Move the mouse over the lightbulb, and the hint should pop up. Of
course, the less hints you need, the better.
- difficulty: The other information shows the difficulty of the exercise (ona scale from 1 to 5). Again, move over the image and the difficulty rating should pop up. The more plus-signs you see, the more difficult the exercise.
SQL Exercises
- alle Mitglieder
all members
difficulty - alle Fahrzeuge
all vehicles
difficulty - Aktuelles Datum und Uhrzeit
current date and time
hint, difficulty - die Namen aller Personen
the names of all persons
hint, difficulty - die Namen aller persoenlichen Mitglieder
the names of all person members
hint, difficulty - die Namen und Heimatstationen der persoenlichen Mitglieder, sortiert nach Station
the names and home location of the person members, in the order of the home locations
hint, difficulty - die Namen und Heimatstation der Genossenschaftsmitglieder, sortiert nach Namen der Heimatstation
names and home locations of the coop members sorted by home location name
hint, difficulty - die Namen der persoenlichen Mitglieder zusammen mit der Angabe, ob sie bereits einen Unfall hatten
the names of the person members plus the indication if the members have had an accident
difficulty - die Namen der persoenlichen Mitglieder zusammen mit der Angabe, ob sie bereits einen Unfall hatten (schoen formattiert)
the names of the person members plus the indication if the members have had an accident (nicely formattted)
hint, difficulty - welche Mitglieder hatten bereits einen Unfall?
which person members have had an accident?
hint, difficulty - die Mitgliedsnummern und Jahresgebuehren der persoenlichen Mitglieder
the member numbers and yearly fees of the person members
hint, difficulty - die Mitgliedsnummern und Jahresgebuehren der Firmenmitglieder
the member numbers and yearly fees of the company members
hint, difficulty - die Mitgliedsnummern und Jahresgebuehren der Genossenschaftsmitglieder
the member numbers and yearly fees of the coop members
hint, difficulty - die Mitgliedsnummern und Jahresgebuehren aller Mitglieder
the member numbers and yearly fees of all members
hint, difficulty - die Kennzeichen, Marken und Modelle aller Fahrzeuge
the licenseplate, make, and model of all vehicles
difficulty - die Marken und Modelle der Fahrzeuge mit Heimatstation
Make, model, and name of the home location of the vehicles
hint, difficulty - die Marken und Modelle der Fahrzeuge mit Heimatstation. Auch die Fahrzeuge ohne Heimatstation sollen angezeigt werden.
Make, model, and name of the home location of the vehicles. The make and model of vehicles without home location should be shown as well
hint, difficulty - die Marken und Modelle der Fahrzeuge mit Heimatstation. Auch die Fahrzeuge ohne Heimatstation und die Stationen ohne Fahrzeuge sollen angezeigt werden.
Make, model, and name of the home location of the vehicles. The make and model of vehicles without home location as well as the locations without vehicles should be shown as well
hint, difficulty - Fahrzeuge ohne Heimatstation
Vehicles without a home location
hint, difficulty - Stationen ohne Fahrzeuge
Locations without vehicles
hint, difficulty - die Kuerzel, Namen und Addressen der Stationen
short name, long name, and address of the locations
difficulty - die Kuerzel, Namen und Orte der Stationen
short name, long name, and city of the locations
hint, difficulty - die Reservationen des Fahrzeugs 'ZH-1020'
the reservation of vehicle 'ZH-1020'
hint, difficulty - die Reservationen des Mitglieds mit der Nummer 1000
the reservations of the member with member number 1000
hint, difficulty - die offenen Reservationen des Mitglieds mit der Nummer 1000
open reservations of the member number 1000
hint, difficulty - alle Reservation, die noch nicht in Rechnung gestellt wurden
all reservations that have not yet been billed
difficulty - alle Benutzer, die fern der Heimat reserviert haben (Fahrzeugstandort ungleich Heimatstandort des Benutzers)
all members who have reserved a vehicle at a location other than their home location
difficulty - alle Benutzer, die fern der Heimat reserviert haben (Fahrzeugstandort ungleich Heimatstandort des Benutzers), obwohl es den Fahrzeugtyp an der Heimatstation gibt
all members who have reserved a vehicle at a location other than their home location even though the vehicle type exists at their home location
hint, difficulty - alle Benutzer, die fern der Heimat reserviert haben (Fahrzeugstandort ungleich Heimatstandort des Benutzers), obwohl es den Fahrzeugtyp an der Heimatstation gibt und eines der Fahrzeuge des gewuenschten Typs frei war/wäre.
all members who have reserved a vehicle at a location other than their home location even though the vehicle type exists at their home location and a vehicle of the desired time would be free during the interval in question
hint, difficulty - die Rechnungen des Mitglieds mit der Nummer 1000
the invoices for member number 1000
difficulty - die Kennzeichen der Fahrzeuge der Benutzungen
the license plates of the vehicles who have been used (not only reserved)
difficulty - die den einzelnen Benutzungen zugrundeliegenden Kilometerpreise
the correct price per kilometer for each use
hint, difficulty - Entfernungsbasierte Kosten der Benutzungen
the distance-based prices for the vehicle uses
hint, difficulty - Die Summe der Benutzungsdauern pro Tag
the sum (of hours) of vehicle uses per day
hint, difficulty - Die durchschnittliche Benutzungsdauer
The average duration of vehicle use
difficulty - die kürzeste Entfernung, die während einer Benutzung zurückgelegt wurde
The shortest distance (in kilometers) driven in a single vehicle use
difficulty - die durchschnittliche Entfernung pro Benutzung
the average distance driven per vehicle use
difficulty - die Summe der Entfernungen, die pro Fahrzeug zurückgelegt wurde
the sum of distances driven per vehicle
hint, difficulty - die durchschnittliche Entfernungen, die pro Fahrzeug zurückgelegt wurde (in allen Reservationen)
the average distance driven per vehicle (in all reservations)
hint, difficulty - Die Stationen, die Anzahl der gemieteten Parkplätze und die monatliche Mietgebühr
The locations, the number of leased parking spaces and the monthly lease (for the parking spaces)
difficulty - Parkplatzmiete (pro Parkplatz) pro Station
locations and the parking space lease per parking space
difficulty - Anzahl freie Parkplaetze pro Station
number of free parking spaces per location
hint, difficulty - Gesamtkosten aller Parkplaetze
total sum of parking space lease (across all locations)
hint, difficulty - alle Rechnungen
all invoices
difficulty - alle offenen Rechnungen
all open invoices (unpaid)
difficulty - alle ueberfaelligen Rechnungen
all overdue invoices
hint, difficulty - alle saeumigen Mitglieder
the members with due and open invoices
difficulty - alle saeumigen persoenlichen Mitglieder
the person members with due and open invoices
hint, difficulty - die Namen der saeumigen persoenlichen Mitglieder
the full names of person members with due and open invoices
hint, difficulty - die Namen der saeumigen persoenlichen Mitglieder (nun jedes Mitglied nur einmal !)
the full names of person members with due and open invoices (make sure that each name appears only once)
difficulty - alle Fahrzeuge
all vehicles
difficulty - alle Personenwagen
all motor cars
difficulty - alle Limousinen
all limousines
difficulty - alle Fahrzeuge in Zürich
all vehicles whose home location is in the city of Zurich
hint, difficulty - alle persoenlichen Mitglieder, die in einem Ort wohnen, in dem es eine Station mit Limousinen gibt
all person members living in a city with a location which has limousines
hint, difficulty - die Anzahl Limousinen pro Station
the locations and number of limousines at each location
difficulty - die Reservationsen fuer Fahrzeuge beliebigen Typs an der station ust
all reservations for vehicles of any category at the location ust
difficulty - die Reservationsen fuer Fahrzeuge beliebigen Typs an der station ust am 11.11.2014 von 9-10 Uhr
all reservations for vehicles of any category at the location ust on 11.11.2015 at 9-10
hint, difficulty - alle Fahrzeuge beliebigen Typs, die am 11.11.2014 um 9:00 Uhr frei waren
all vehicles which are free on 11.11.2015 at 9:00
hint, difficulty - alle Fahrzeuge beliebigen Typs an der Station ust, die am 11.11.2014 um 9:00 Uhr frei waren
all vehicles at location ust which are free on 11.11.2015 at 9:00
hint, difficulty - alle PKWs mit Kindersitz an der Station grs, die am 11.11.2014 um 9:00 Uhr frei waren
all motor cars with a child seat at location ust which are free on 11.11.2015 at 9:00
hint, difficulty - Kennzeichen mit der Angabe, ob das Fahrzeug am 09.09.2014 von 9-10 Uhr frei war
all license plates together with the information whether the vehicle was free on 09.09.2015 from 9-10
hint, difficulty - die Kennzeichen der Fahrzeuge zusammen mit der Anzahl der Reservationen am 11.11.2014 von 9-10 Uhr
all license plates with the number of reservations free on 09.09.2015 from 9-10
hint, difficulty - die Kuerzel der Stationen zusammen mit der Anzahl der Fahrzeuge, die am 11.11.2014 von 9-10 Uhr frei sind
the short names of locations with the number of vehicles at each location which are free on 11.11.2014 from 9-10
hint, difficulty - Benutzer ohne Reservationen
members without any reservations
hint, difficulty - die Kennzeichen und Anzahl der Reservationen der einzelnen Fahrzeuge
the license plates and number of reservations of each vehicle
hint, difficulty - der hoechste Kilometerstand eines Fahrzeugs
the maximum odometer value
hint, difficulty - das Fahrzeug mit dem hoechsten Kilometerstand
the vehicle with the highest odometer value
hint, difficulty - der höchste Benzinverbrauch eines Fahrzeugs
the highest fuel consumption of all vehicles
hint, difficulty - das Fahrzeug mit dem höchsten Benzinverbrauch
the vehicle with the highest fuel consumption
hint, difficulty - die Anzahl Limousinen pro Station
the number of limousines per location
hint, difficulty - die maximale Anzahl Limousinen an einer Station
the highest number of limousines per location
hint, difficulty - Die Station mit der maximalen Anzahl Limos
the location with the highest number of limousines
hint, difficulty - alle Stationen, die (ueber die Nachbarschaftsbeziehung) in maximal vier Schritten von Mönchaltorf (moe) erreichbar sind
all locations that are reachable (via the nextLocation relationship) in no more than four steps from location moe
hint, difficulty - ein Belegungsplan fuer das Auto '194 SUA' fuer den 11.11. 2014 und die folgenden beiden Tage
a free/busy plan for the vehicle '194 SUA' for 11.11. 2015 and the following two days
hint, difficulty - ein Belegungsplan fuer die Station Greifensee fuer den 11.11. 2014
a free/busy plan for the location Greifensee for 11.11. 2015
hint, difficulty - die Kennzeichen und Anzahl der Reservationen der einzelnen Fahrzeuge, absteigend sortiert nach Anzahl der Reservationen, zusammen mit der kummulierten Summe der Reservationen und dem Anteil des Fahrzeugs an dieser kummulierten Summe (kummulierte Summe = Summe der Reservationen aller Fahrzeuge bis einschliesslich des aktuellen in der Liste)
the license plates and number of reservations per vehicle. order should be by number of reservations (largest to smallest). Also compute the cummulated sum of the reservations and the contribution of the current vehicle to the cummulated sum
hint, difficulty - der durchschnittliche Spritverbrauch pro Fahrzeug
the average fuel consumption (per 100km) per vehicle
difficulty - der maximale durchschnittliche Spritverbrauch pro Fahrzeug
the highest average fuel consumption per vehicle
hint, difficulty - das Fahrzeug mit dem maximalen Spritverbrauch
the vehicle with the highest average fuel consumption
hint, difficulty - der maximale, minimale und durchschnittliche Spritverbrauch pro Fahrzeugtyp
the highest, average, and smallest average fuel consumption by vehicle category
hint, difficulty - maximaler Spritverbrauch pro Fahrzeug und Benutzer
the highest fuel consumption by member and vehicle (for a single reservation)
hint, difficulty - der Benutzer und das Fahrzeug mit dem hoechsten Benzinverbrauch (für eine einzelne Benutzung)
member and vehicle with the highest fuel consumption (for a single reservation)
hint, difficulty - das Fahrzeug mit dem maximalen Spritverbrauch
the vehicle with the highest fuel consumption (NOT per kilometer)
hint, difficulty - Kategorien und der höchste Kilometerstand pro Kategorie
Vehicle categories and the highest odometer value for each category
hint, difficulty - Kategorien und der höchste Kilometerstand pro Kategorie sowie das Kennzeichen des Fahrzeugs (dieser Kategorie) mit diesem Kilometerstand
Vehicle categories and the highest odometer value for each category, plus the license plate of the vehicle with this odometer value
hint, difficulty - Die Benutzungsdauern der Reservationen
the duration of the reservations
hint, difficulty - Die Benutzungsdauern der Reservationen (jeden Wert nur einmal)
the duration of the reservations, list each value only once
difficulty - Die Benutzungsdauern der Reservationen (jeden Wert nur einmal), die längste Benutzung zuerst
the duration of the reservations, list each value only once and sort from largest to smallest
difficulty - Ein Histogramm der Benutzungsdauern der Reservationen, d.h. zu jeder Dauer die Angabe, wie oft sie vorkommt
a histogram of reservation durations, i.e., for each duration calculate how often it occurs
difficulty - Die Summe der Reservationen für alle Fahrzeuge ab dem 7.7.2015 für die nächsten 1000 Stunden
The sum of reservation durations for all vehicles starting on 7.7.2015 for the next 1000 hours
hint, difficulty - Jahr und Monat der Reservationen (jede Kombination nur einmal)
year and month of reservations (each combination only once)
hint, difficulty - Jahr und Monat der Reservationen und Anzahl der Reservationen in diesem Monat (ausschlaggebend ist der Reservationsbeginn)
year and month of reservations and number of reservations during this month (use reservation begin)
hint, difficulty - Jahr und Monat der Reservationen und Summe der Reservationsdauern in diesem Monat (ausschlaggebend ist der Reservationsbeginn)
year and month of reservations and sum of reservation durations during this month (use reservation begin)
hint, difficulty - Jahr und Monat der Reservationen und Anzahl der Reservationen in diesem Monat (ausschlaggebend ist der Reservationsbeginn); und Bildung einer Rangliste innerhalb der einzelnen Jahre
year and month of reservations and number of reservations during this month (use reservation begin). Sort according to number of reservations within each year
hint, difficulty - gleich wie oben, Summe der Reservationsdauern anstatt Anzahl Reservationen
same as above, but use sum of reservation durations instead of reservation count
hint, difficulty - Jahr und Monat der Reservationen und Summe der Reservationsdauern in diesem Monat (ausschlaggebend ist der Reservationsbeginn); und Bildung einer Rangliste innerhalb der einzelnen Jahre. Ausgabe der auf der Rangliste führenden beiden Monate
same as above, but use sum of reservation durations instead of reservation count. Return only the first two months
hint, difficulty - gleitender 3-Monatsdurchschnitt der Reservationsanzahlen
calculate the 3-months moving average of reservation counts
hint, difficulty - monatsweise kummulierte Summe der Reservationszahlen innerhalb eines Jahres
calculate the cumulated sums of monthly reservation counts per year
hint, difficulty - Einteilung der Monate des Jahres 2014 in Tertile (drei Quantile) gemäss der Anzahl Reservationen
assign the months of the year 2015 to tertiles (three quantiles) based on the number of reservations per month
hint, difficulty