Navigation auf uzh.ch

Suche

Department of Informatics Database Technology

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

  1. alle Mitglieder
    all members
    difficulty
    Topics:01-Fundamentals

  2. alle Fahrzeuge
    all vehicles
    difficulty
    Topics:01-Fundamentals

  3. alle Personenwagen
    all motor cars
    difficulty
    Topics:01-Fundamentals

  4. alle Limousinen
    all limousines
    difficulty
    Topics:01-Fundamentals

  5. Aktuelles Datum und Uhrzeit
    current date and time
    hint difficulty
    Topics:01-Fundamentals

  6. 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)
    hint difficulty
    Topics:01-Fundamentals

  7. die Namen aller persoenlichen Mitglieder
    the names of all person members
    hint difficulty
    Topics:01-Fundamentals

  8. 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
    Topics:01-Fundamentals

  9. 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
    Topics:02-Joins

  10. die Kennzeichen, Marken und Modelle aller Fahrzeuge
    the licenseplate, make, and model of all vehicles
    difficulty
    Topics:01-Fundamentals

  11. die Marken und Modelle der Fahrzeuge mit Namen der Heimatstation
    Make, model, and name of the home location of the vehicles
    hint difficulty
    Topics:02-Joins

  12. 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
    hint difficulty
    Topics:02-Joins

  13. 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
    Topics:02-Joins

  14. Fahrzeuge ohne Heimatstation
    Vehicles without a home location
    hint difficulty
    Topics:01-Fundamentals

  15. Stationen ohne Fahrzeuge
    Locations without vehicles
    hint difficulty
    Topics:02-Joins

  16. die Kuerzel, Namen und Addressen der Stationen
    short name, long name, and address of the locations
    difficulty
    Topics:01-Fundamentals

  17. die Kuerzel, Namen und Orte der Stationen
    short name, long name, and city of the locations
    hint difficulty
    Topics:01-Fundamentals

  18. die Reservationen des Fahrzeugs 'ZH-1020'
    the reservation of vehicle 'ZH-1020'
    hint difficulty
    Topics:02-Joins

  19. die Reservationen des Mitglieds mit der Nummer 1000
    the reservations of the member with member number 1000
    hint difficulty
    Topics:02-Joins

  20. die offenen (zukünftigen) Reservationen des Mitglieds mit der Nummer 1000
    open (future) reservations of the member number 1000
    hint difficulty
    Topics:02-Joins

  21. alle Fahrzeuge in Zürich
    all vehicles whose home location is in the city of Zurich
    hint difficulty
    Topics:01-Fundamentals

  22. die Anzahl Limousinen pro Station
    the locations and number of limousines at each location
    difficulty
    Topics:03-Aggregates (w/ or w/o grouping) 02-Joins

  23. alle offenen (unbezahlten) Rechnungen
    all open invoices (unpaid)
    difficulty
    Topics:01-Fundamentals

  24. alle ueberfaelligen Rechnungen
    all overdue invoices
    hint difficulty
    Topics:01-Fundamentals

  25. alle Reservationen, die noch nicht in Rechnung gestellt wurden
    all reservations that have not yet been billed
    hint difficulty
    Topics:02-Joins

  26. die Rechnungen des Mitglieds mit der Nummer 1000
    the invoices for member number 1000
    difficulty
    Topics:02-Joins

  27. die Kennzeichen der Fahrzeuge der Benutzungen
    the license plates of the vehicles which have been used (not only reserved)
    difficulty
    Topics:02-Joins

  28. 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
    Topics:01-Fundamentals

  29. 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
    Topics:01-Fundamentals

  30. welche persoenlichen Mitglieder hatten bereits einen Unfall?
    which person members have had an accident?
    hint difficulty
    Topics:01-Fundamentals

  31. die den einzelnen Benutzungen zugrundeliegenden Kilometerpreise
    the correct price per kilometer for each use
    hint difficulty
    Topics:02-Joins

  32. Entfernungsbasierte Kosten der Benutzungen
    the distance-based prices for the vehicle uses
    hint difficulty
    Topics:02-Joins

  33. Die Summe der Benutzungsdauern pro Tag
    the sum (of hours) of vehicle uses per day
    hint difficulty
    Topics:03-Aggregates (w/ or w/o grouping)

  34. Die durchschnittliche Benutzungsdauer
    The average duration of vehicle use
    difficulty
    Topics:03-Aggregates (w/ or w/o grouping)

  35. die kürzeste Entfernung, die während einer Benutzung zurückgelegt wurde
    The shortest distance (in kilometers) driven in a single vehicle use
    difficulty
    Topics:03-Aggregates (w/ or w/o grouping)

  36. die durchschnittliche Entfernung pro Benutzung
    the average distance driven per vehicle use
    difficulty
    Topics:03-Aggregates (w/ or w/o grouping)

  37. die Summe der Entfernungen, die pro Fahrzeug zurückgelegt wurde
    the sum of distances driven per vehicle
    hint difficulty
    Topics:03-Aggregates (w/ or w/o grouping) 02-Joins

  38. die durchschnittliche Entfernungen, die pro Fahrzeug zurückgelegt wurde (in allen Reservationen)
    the average distance driven per vehicle (in all reservations)
    hint difficulty
    Topics:03-Aggregates (w/ or w/o grouping)

  39. die Namen und Jahresgebuehren der persoenlichen Mitglieder
    the names and yearly fees of the person members
    hint difficulty
    Topics:02-Joins

  40. die Namen und Jahresgebuehren der Firmenmitglieder
    the names and yearly fees of the company members
    hint difficulty
    Topics:02-Joins

  41. die Namen und Jahresgebuehren der Genossenschaftsmitglieder
    the names and yearly fees of the coop members
    hint difficulty
    Topics:02-Joins

  42. die Namen und Jahresgebuehren aller Mitglieder
    the names and yearly fees of all members
    hint difficulty
    Topics:02-Joins

  43. alle saeumigen Mitglieder
    the members with due and open invoices
    difficulty
    Topics:02-Joins

  44. alle saeumigen persoenlichen Mitglieder
    the person members with due and open invoices
    hint difficulty
    Topics:02-Joins

  45. die Namen der saeumigen persoenlichen Mitglieder
    the full names of person members with due and open invoices
    hint difficulty
    Topics:02-Joins

  46. 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
    Topics:02-Joins

  47. 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
    Topics:05-Subqueries 02-Joins

  48. die Reservationsen fuer Fahrzeuge beliebigen Typs an der station ust
    all reservations for vehicles of any category at the location ust
    difficulty
    Topics:02-Joins

  49. die Reservationsen fuer Fahrzeuge beliebigen Typs an der station ust am 11.11.2023 von 9-10 Uhr
    all reservations for vehicles of any category at the location ust on 11.11.2023 at 9-10
    hint difficulty
    Topics:02-Joins

  50. alle Fahrzeuge beliebigen Typs, die am 11.11.2023 um 9:00 Uhr frei waren
    all vehicles which are free on 11.11.2023 at 9:00
    hint difficulty
    Topics:05-Subqueries

  51. alle Fahrzeuge beliebigen Typs an der Station ust, die am 11.11.2023 um 9:00 Uhr frei waren
    all vehicles at location ust which are free on 11.11.2023 at 9:00
    hint difficulty
    Topics:05-Subqueries

  52. alle PKWs mit Kindersitz an der Station grs, die am 11.11.2023 um 9:00 Uhr frei waren
    all motor cars with a child seat at location ust which are free on 11.11.2023 at 9:00
    hint difficulty
    Topics:05-Subqueries

  53. Kennzeichen mit der Angabe, ob das Fahrzeug am 11.11..2023 von 9-10 Uhr frei war
    all license plates together with the information whether the vehicle was free on 11.11..2023 from 9-10
    hint difficulty
    Topics:01-Fundamentals

  54. die Kennzeichen der Fahrzeuge zusammen mit der Anzahl der Reservationen am 11.11.2023 von 9-10 Uhr
    all license plates with the number of reservations free on 09.09.2023 from 9-10
    hint difficulty
    Topics:03-Aggregates (w/ or w/o grouping) 05-Subqueries

  55. die Kuerzel der Stationen zusammen mit der Anzahl der Fahrzeuge, die am 11.11.2023 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.2023 from 9-10
    hint difficulty
    Topics:03-Aggregates (w/ or w/o grouping) 05-Subqueries

  56. Benutzer ohne Reservationen
    members without any reservations
    hint difficulty
    Topics:02-Joins

  57. die Kennzeichen und Anzahl der Reservationen der einzelnen Fahrzeuge
    the license plates and number of reservations of each vehicle
    hint difficulty
    Topics:03-Aggregates (w/ or w/o grouping) 02-Joins

  58. der hoechste Kilometerstand eines Fahrzeugs
    the maximum odometer value
    hint difficulty
    Topics:03-Aggregates (w/ or w/o grouping)

  59. das Fahrzeug mit dem hoechsten Kilometerstand
    the vehicle with the highest odometer value
    hint difficulty
    Topics:04-Aggregates (finding extreme values) 05-Subqueries

  60. der höchste Benzinverbrauch eines Fahrzeugs
    the highest fuel consumption of all vehicles
    hint difficulty
    Topics:03-Aggregates (w/ or w/o grouping)

  61. das Fahrzeug mit dem höchsten Benzinverbrauch
    the vehicle with the highest fuel consumption
    hint difficulty
    Topics:04-Aggregates (finding extreme values) 05-Subqueries

  62. die Anzahl Limousinen pro Station
    the number of limousines per location
    hint difficulty
    Topics:03-Aggregates (w/ or w/o grouping) 02-Joins

  63. die maximale Anzahl Limousinen an einer Station
    the highest number of limousines per location
    hint difficulty
    Topics:03-Aggregates (w/ or w/o grouping) 02-Joins

  64. Die Station mit der maximalen Anzahl Limos
    the location with the highest number of limousines
    hint difficulty
    Topics:04-Aggregates (finding extreme values) 02-Joins

  65. 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
    Topics:08-Recursive Queries

  66. der durchschnittliche Spritverbrauch pro Fahrzeug
    the average fuel consumption (per 100km) per vehicle
    difficulty
    Topics:01-Fundamentals

  67. der maximale durchschnittliche Spritverbrauch pro Fahrzeug
    the highest average fuel consumption per vehicle
    hint difficulty
    Topics:04-Aggregates (finding extreme values)

  68. das Fahrzeug mit dem maximalen Spritverbrauch
    the vehicle with the highest average fuel consumption
    hint difficulty
    Topics:04-Aggregates (finding extreme values)

  69. der maximale, minimale und durchschnittliche Spritverbrauch pro Fahrzeugtyp
    the highest, average, and smallest average fuel consumption by vehicle category
    hint difficulty
    Topics:03-Aggregates (w/ or w/o grouping)

  70. maximaler Spritverbrauch pro Fahrzeug und Benutzer
    the highest fuel consumption by member and vehicle (for a single reservation)
    hint difficulty
    Topics:03-Aggregates (w/ or w/o grouping) 02-Joins

  71. 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
    Topics:04-Aggregates (finding extreme values)

  72. das Fahrzeug mit dem maximalen Spritverbrauch
    the vehicle with the highest fuel consumption (NOT per kilometer)
    hint difficulty
    Topics:04-Aggregates (finding extreme values)

  73. Kategorien und der höchste Kilometerstand pro Kategorie
    Vehicle categories and the highest odometer value for each category
    hint difficulty
    Topics:03-Aggregates (w/ or w/o grouping)

  74. 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
    Topics:04-Aggregates (finding extreme values)

  75. Die Benutzungsdauern der Reservationen
    the duration of the reservations
    hint difficulty
    Topics:01-Fundamentals

  76. Die Benutzungsdauern der Reservationen (jeden Wert nur einmal)
    the duration of the reservations, list each value only once
    difficulty
    Topics:01-Fundamentals

  77. 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
    Topics:01-Fundamentals

  78. 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
    Topics:03-Aggregates (w/ or w/o grouping)

  79. 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
    Topics:06-Local Grouping (window functions)

  80. Jahr und Monat der Reservationen (Reservationsbeginn, jede Kombination nur einmal)
    year and month of reservations (reservation begin; each combination only once)
    hint difficulty
    Topics:01-Fundamentals

  81. 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
    Topics:03-Aggregates (w/ or w/o grouping)

  82. 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
    Topics:03-Aggregates (w/ or w/o grouping)

  83. 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
    Topics:06-Local Grouping (window functions)

  84. gleich wie oben, Summe der Reservationsdauern anstatt Anzahl Reservationen
    same as above, but use sum of reservation durations instead of reservation count
    hint difficulty
    Topics:06-Local Grouping (window functions)

  85. 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
    Topics:06-Local Grouping (window functions)

  86. gleitender 3-Monatsdurchschnitt der Reservationsanzahlen
    calculate the 3-months moving average of reservation counts
    hint difficulty
    Topics:06-Local Grouping (window functions)

  87. monatsweise kummulierte Summe der Reservationszahlen innerhalb eines Jahres
    calculate the cumulated sums of monthly reservation counts per year
    hint difficulty
    Topics:06-Local Grouping (window functions)

  88. Einteilung der Monate des Jahres 2023 in Tertile (drei Quantile) gemäss der Anzahl Reservationen
    assign the months of the year 2023 to tertiles (three quantiles) based on the number of reservations per month
    hint difficulty
    Topics:06-Local Grouping (window functions)

  89. Anzahl Reservationen gruppiert nach den Dimensionen Mitglied, Fahrzeug, Station
    The number of reservations grouped over the dimensions member, vehicle, and location
    hint difficulty
    Topics:07-Super groups 02-Joins

  90. 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.
    hint difficulty
    Topics:07-Super groups 02-Joins

  91. 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.
    hint difficulty
    Topics:07-Super groups 02-Joins

  92. 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.
    hint difficulty
    Topics:07-Super groups 02-Joins

  93. 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
    hint difficulty
    Topics:07-Super groups 02-Joins

  94. 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
    difficulty
    Topics:02-Joins

  95. 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
    hint difficulty
    Topics:05-Subqueries 02-Joins

  96. 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
    hint difficulty
    Topics:05-Subqueries 02-Joins

  97. ein Belegungsplan fuer das Auto '194 SUA' fuer den 11.11. 2023 und die folgenden beiden Tage
    a free/busy plan for the vehicle '194 SUA' for 11.11. 2023 and the following two days
    hint difficulty
    Topics:08-Recursive Queries

  98. ein Belegungsplan fuer die Station Greifensee fuer den 11.11. 2023
    a free/busy plan for the location Greifensee for 11.11. 2023
    hint difficulty
    Topics:08-Recursive Queries