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 text "hint" or the light bulb, if it is displayed, 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 (on a scale from 1 to 5). Again, move the cursor over the text "difficulty" or the tinguely machine and the difficulty rating should pop up. The more plus-signs you see, the more difficult the exercise.
SQL Exercises
- alle Mitglieder
all members
Topics:01-Fundamentals - alle Fahrzeuge
all vehicles
Topics:01-Fundamentals - alle Personenwagen
all motor cars
Topics:01-Fundamentals - alle Limousinen
all limousines
Topics:01-Fundamentals - Aktuelles Datum und Uhrzeit
current date and time
Topics:01-Fundamentals - die vollen Namen aller Personen (Wenn nicht anders spezifiziert, ist ab jetzt mit “Name†immer der volle Name, d.h. “vorname nachnameâ€, gemeint)
the full names of all persons (unless specified otherwise, from now on the full name, “firstname lastname†is required whenever “name†is mentioned)
Topics:01-Fundamentals - die Namen aller persoenlichen Mitglieder
the names of all person members
Topics:01-Fundamentals - 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
Topics:01-Fundamentals - die Namen und Heimatstation der Genossenschaftsmitglieder, sortiert nach Namen der Heimatstation
names and home locations of the coop members sorted by home location name
Topics:02-Joins - die Kennzeichen, Marken und Modelle aller Fahrzeuge
the licenseplate, make, and model of all vehicles
Topics:01-Fundamentals - die Marken und Modelle der Fahrzeuge mit Namen der Heimatstation
Make, model, and name of the home location of the vehicles
Topics:02-Joins - die Marken und Modelle der Fahrzeuge mit dem Namen der 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
Topics:02-Joins - 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
Topics:02-Joins - Fahrzeuge ohne Heimatstation
Vehicles without a home location
Topics:01-Fundamentals - Stationen ohne Fahrzeuge
Locations without vehicles
Topics:02-Joins - die Kuerzel, Namen und Addressen der Stationen
short name, long name, and address of the locations
Topics:01-Fundamentals - die Kuerzel, Namen und Orte der Stationen
short name, long name, and city of the locations
Topics:01-Fundamentals - die Reservationen des Fahrzeugs 'ZH-1020'
the reservation of vehicle 'ZH-1020'
Topics:02-Joins - die Reservationen des Mitglieds mit der Nummer 1000
the reservations of the member with member number 1000
Topics:02-Joins - die offenen (zukünftigen) Reservationen des Mitglieds mit der Nummer 1000
open (future) reservations of the member number 1000
Topics:02-Joins - alle Fahrzeuge in Zürich
all vehicles whose home location is in the city of Zurich
Topics:01-Fundamentals - die Anzahl Limousinen pro Station
the locations and number of limousines at each location
Topics:03-Aggregates (w/ or w/o grouping) 02-Joins - alle offenen (unbezahlten) Rechnungen
all open invoices (unpaid)
Topics:01-Fundamentals - alle ueberfaelligen Rechnungen
all overdue invoices
Topics:01-Fundamentals - alle Reservationen, die noch nicht in Rechnung gestellt wurden
all reservations that have not yet been billed
Topics:02-Joins - die Rechnungen des Mitglieds mit der Nummer 1000
the invoices for member number 1000
Topics:02-Joins - die Kennzeichen der Fahrzeuge der Benutzungen
the license plates of the vehicles which have been used (not only reserved)
Topics:02-Joins - 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
Topics:01-Fundamentals - 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)
Topics:01-Fundamentals - welche persoenlichen Mitglieder hatten bereits einen Unfall?
which person members have had an accident?
Topics:01-Fundamentals - die den einzelnen Benutzungen zugrundeliegenden Kilometerpreise
the correct price per kilometer for each use
Topics:02-Joins - Entfernungsbasierte Kosten der Benutzungen
the distance-based prices for the vehicle uses
Topics:02-Joins - Die Summe der Benutzungsdauern pro Tag
the sum (of hours) of vehicle uses per day
Topics:03-Aggregates (w/ or w/o grouping) - Die durchschnittliche Benutzungsdauer
The average duration of vehicle use
Topics:03-Aggregates (w/ or w/o grouping) - die kürzeste Entfernung, die während einer Benutzung zurückgelegt wurde
The shortest distance (in kilometers) driven in a single vehicle use
Topics:03-Aggregates (w/ or w/o grouping) - die durchschnittliche Entfernung pro Benutzung
the average distance driven per vehicle use
Topics:03-Aggregates (w/ or w/o grouping) - die Summe der Entfernungen, die pro Fahrzeug zurückgelegt wurde
the sum of distances driven per vehicle
Topics:03-Aggregates (w/ or w/o grouping) 02-Joins - die durchschnittliche Entfernungen, die pro Fahrzeug zurückgelegt wurde (in allen Reservationen)
the average distance driven per vehicle (in all reservations)
Topics:03-Aggregates (w/ or w/o grouping) - die Namen und Jahresgebuehren der persoenlichen Mitglieder
the names and yearly fees of the person members
Topics:02-Joins - die Namen und Jahresgebuehren der Firmenmitglieder
the names and yearly fees of the company members
Topics:02-Joins - die Namen und Jahresgebuehren der Genossenschaftsmitglieder
the names and yearly fees of the coop members
Topics:02-Joins - die Namen und Jahresgebuehren aller Mitglieder
the names and yearly fees of all members
Topics:02-Joins - alle saeumigen Mitglieder
the members with due and open invoices
Topics:02-Joins - alle saeumigen persoenlichen Mitglieder
the person members with due and open invoices
Topics:02-Joins - die Namen der saeumigen persoenlichen Mitglieder
the full names of person members with due and open invoices
Topics:02-Joins - 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)
Topics:02-Joins - 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
Topics:05-Subqueries 02-Joins - die Reservationsen fuer Fahrzeuge beliebigen Typs an der station ust
all reservations for vehicles of any category at the location ust
Topics:02-Joins - die Reservationsen fuer Fahrzeuge beliebigen Typs an der station ust am 11.11.2024 von 9-10 Uhr
all reservations for vehicles of any category at the location ust on 11.11.2024 at 9-10
Topics:02-Joins - alle Fahrzeuge beliebigen Typs, die am 11.11.2024 um 9:00 Uhr frei waren
all vehicles which are free on 11.11.2024 at 9:00
Topics:05-Subqueries - alle Fahrzeuge beliebigen Typs an der Station ust, die am 11.11.2024 um 9:00 Uhr frei waren
all vehicles at location ust which are free on 11.11.2024 at 9:00
Topics:05-Subqueries - alle PKWs mit Kindersitz an der Station grs, die am 11.11.2024 um 9:00 Uhr frei waren
all motor cars with a child seat at location ust which are free on 11.11.2024 at 9:00
Topics:05-Subqueries - Kennzeichen mit der Angabe, ob das Fahrzeug am 11.11..2024 von 9-10 Uhr frei war
all license plates together with the information whether the vehicle was free on 11.11..2024 from 9-10
Topics:01-Fundamentals - die Kennzeichen der Fahrzeuge zusammen mit der Anzahl der Reservationen am 11.11.2024 von 9-10 Uhr
all license plates with the number of reservations free on 09.09.2024 from 9-10
Topics:03-Aggregates (w/ or w/o grouping) 05-Subqueries - die Kuerzel der Stationen zusammen mit der Anzahl der Fahrzeuge, die am 11.11.2024 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.2024 from 9-10
Topics:03-Aggregates (w/ or w/o grouping) 05-Subqueries - Benutzer ohne Reservationen
members without any reservations
Topics:02-Joins - die Kennzeichen und Anzahl der Reservationen der einzelnen Fahrzeuge
the license plates and number of reservations of each vehicle
Topics:03-Aggregates (w/ or w/o grouping) 02-Joins - der hoechste Kilometerstand eines Fahrzeugs
the maximum odometer value
Topics:03-Aggregates (w/ or w/o grouping) - das Fahrzeug mit dem hoechsten Kilometerstand
the vehicle with the highest odometer value
Topics:04-Aggregates (finding extreme values) 05-Subqueries - der höchste Benzinverbrauch eines Fahrzeugs
the highest fuel consumption of all vehicles
Topics:03-Aggregates (w/ or w/o grouping) - das Fahrzeug mit dem höchsten Benzinverbrauch
the vehicle with the highest fuel consumption
Topics:04-Aggregates (finding extreme values) 05-Subqueries - die Anzahl Limousinen pro Station
the number of limousines per location
Topics:03-Aggregates (w/ or w/o grouping) 02-Joins - die maximale Anzahl Limousinen an einer Station
the highest number of limousines per location
Topics:03-Aggregates (w/ or w/o grouping) 02-Joins - Die Station mit der maximalen Anzahl Limos
the location with the highest number of limousines
Topics:04-Aggregates (finding extreme values) 02-Joins - 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
Topics:08-Recursive Queries - der durchschnittliche Spritverbrauch pro Fahrzeug
the average fuel consumption (per 100km) per vehicle
Topics:01-Fundamentals - der maximale durchschnittliche Spritverbrauch pro Fahrzeug
the highest average fuel consumption per vehicle
Topics:04-Aggregates (finding extreme values) - das Fahrzeug mit dem maximalen Spritverbrauch
the vehicle with the highest average fuel consumption
Topics:04-Aggregates (finding extreme values) - der maximale, minimale und durchschnittliche Spritverbrauch pro Fahrzeugtyp
the highest, average, and smallest average fuel consumption by vehicle category
Topics:03-Aggregates (w/ or w/o grouping) - maximaler Spritverbrauch pro Fahrzeug und Benutzer
the highest fuel consumption by member and vehicle (for a single reservation)
Topics:03-Aggregates (w/ or w/o grouping) 02-Joins - 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)
Topics:04-Aggregates (finding extreme values) - das Fahrzeug mit dem maximalen Spritverbrauch
the vehicle with the highest fuel consumption (NOT per kilometer)
Topics:04-Aggregates (finding extreme values) - Kategorien und der höchste Kilometerstand pro Kategorie
Vehicle categories and the highest odometer value for each category
Topics:03-Aggregates (w/ or w/o grouping) - 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
Topics:04-Aggregates (finding extreme values) - Die Benutzungsdauern der Reservationen
the duration of the reservations
Topics:01-Fundamentals - Die Benutzungsdauern der Reservationen (jeden Wert nur einmal)
the duration of the reservations, list each value only once
Topics:01-Fundamentals - 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
Topics:01-Fundamentals - 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
Topics:03-Aggregates (w/ or w/o grouping) - 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
Topics:06-Local Grouping (window functions) - Jahr und Monat der Reservationen (Reservationsbeginn, jede Kombination nur einmal)
year and month of reservations (reservation begin; each combination only once)
Topics:01-Fundamentals - 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)
Topics:03-Aggregates (w/ or w/o grouping) - 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)
Topics:03-Aggregates (w/ or w/o grouping) - 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
Topics:06-Local Grouping (window functions) - gleich wie oben, Summe der Reservationsdauern anstatt Anzahl Reservationen
same as above, but use sum of reservation durations instead of reservation count
Topics:06-Local Grouping (window functions) - 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
Topics:06-Local Grouping (window functions) - gleitender 3-Monatsdurchschnitt der Reservationsanzahlen
calculate the 3-months moving average of reservation counts
Topics:06-Local Grouping (window functions) - monatsweise kummulierte Summe der Reservationszahlen innerhalb eines Jahres
calculate the cumulated sums of monthly reservation counts per year
Topics:06-Local Grouping (window functions) - Einteilung der Monate des Jahres 2024 in Tertile (drei Quantile) gemäss der Anzahl Reservationen
assign the months of the year 2024 to tertiles (three quantiles) based on the number of reservations per month
Topics:06-Local Grouping (window functions) - Anzahl Reservationen gruppiert nach den Dimensionen Mitglied, Fahrzeug, Station
The number of reservations grouped over the dimensions member, vehicle, and location
Topics:07-Super groups 02-Joins - Anzahl Reservationen gruppiert nach allen möglichen Kombinationen der Dimensionen Mitglied und Fahrzeugtyp
The number of reservations grouped over all possible combinations of the dimensions member (member number) and vehicle type.
Topics:07-Super groups 02-Joins - Anzahl Reservationen gruppiert nach allen möglichen Kombinationen der Dimensionen Mitglied und Fahrzeugtyp, so dass auch Mitglieder und Fahrzeugtypen ohne Reservationen aufgeführt werden
The number of reservations grouped over all possible combinations of the dimensions member (member number) and vehicle type such that also types and members without reservations are shown.
Topics:07-Super groups 02-Joins - Anzahl Reservationen gruppiert nach allen möglichen Kombinationen der Dimensionen Mitglied und Fahrzeugtyp, so dass auch Mitglieder und Fahrzeugtypen ohne Reservationen aufgeführt werden. Ausserdem sollen All- und Nullwerte unterschieden werden.
The number of reservations grouped over all possible combinations of the dimensions member (member number) and vehicle type such that also types and members without reservations are shown. In addition distinguish all and null values.
Topics:07-Super groups 02-Joins - Anzahl Reservationen hierarchisch gruppiert nach Jahr, Monat und Tag des Reservationsbeginns
The number of reservations hierarchically grouped over year, month, and day of the reservation begin
Topics:07-Super groups 02-Joins - alle Benutzer, die fern der Heimat reserviert haben (Fahrzeugstandort <> Heimatstandort des Benutzers)
all members who have reserved a vehicle at a location other than their home location
Topics:02-Joins - alle Benutzer, die fern der Heimat reserviert haben (Fahrzeugstandort <> 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
Topics:05-Subqueries 02-Joins - alle Benutzer, die fern der Heimat reserviert haben (Fahrzeugstandort <> 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
Topics:05-Subqueries 02-Joins - ein Belegungsplan fuer das Auto '194 SUA' fuer den 11.11. 2024 und die folgenden beiden Tage
a free/busy plan for the vehicle '194 SUA' for 11.11. 2024 and the following two days
Topics:08-Recursive Queries - ein Belegungsplan fuer die Station Greifensee fuer den 11.11. 2024
a free/busy plan for the location Greifensee for 11.11. 2024
Topics:08-Recursive Queries