1 / 13

Übung 1: SQL

Übung 1: SQL. Übungen finden bei Bedarf anstelle der Vorlesungen statt Fragen?  sautter@ira.uka.de. Fragen aus der Vorlesung. Wie sieht eine äquivalente Anfrage zu select Titel from Bücher where ISBN in (select ISBN from Empfiehlt) ohne Schachtelung aus?

skip
Télécharger la présentation

Übung 1: SQL

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Übung 1: SQL Übungen finden bei Bedarf anstelle der Vorlesungen statt Fragen?  sautter@ira.uka.de Übung 1: SQL

  2. Fragen aus der Vorlesung • Wie sieht eine äquivalente Anfrage zuselect Titel from Bücher where ISBN in (select ISBN from Empfiehlt)ohne Schachtelung aus? • select b.titel from Bücher b inner join Empfielt e on b.ISBN = e.ISBN • oder: • select b.titel from Bücher b, Empfielt e where b.ISBN = e.ISBN Übung 1: SQL

  3. Funktion Ergebnis count() min() max() sum() Fragen aus der Vorlesung • Was liefern Aggregatfunktionen, wenn die Relation leer ist oder kein Tupel diewhere-Klausel erfüllt? 0 null null null Übung 1: SQL

  4. Fragen aus der Vorlesung • Ist die Abfrage select * from Person where note = max(note)zulässig? • Nein, korrekt wäre: • select * from Person where note in (select max(note) from Person) • oder: • select * from Person where note = (select max(note) from Person) Übung 1: SQL

  5. Übungsblatt 1 Übung 1: SQL

  6. Übungsblatt 1 Erstellen Sie ein Abfrage, die folgende Informationen liefert: • Namen der Kontinente, Namen der darin gelegenen Länder, sortiert nach Namen der Kontinente und darin nach Namen der Länder • select co.name, ct.name from continent co, country ct, encompasses e where co.name = e.continent and ct.cid = e.cid order by co.name, ct.name Übung 1: SQL

  7. Übungsblatt 1 Erstellen Sie ein Abfrage, die folgende Informationen liefert: • Namen der Kontinente, Anzahl der darin gelegenen Länder, sortiert nach Namen der Kontinente • select co.name, count(ct.name) from continent co, country ct, encompasses e where co.name = e.continent and ct.cid = e.cid group by co.name order by co.name Übung 1: SQL

  8. Übungsblatt 1 Erstellen Sie ein Abfrage, die folgende Informationen liefert: • Namen der Länder, Anzahl ihrer Nachbarländer, sortiert nach Namen der Länder • select co.name, count(b.country1) from country co, borders b where b.country1 = co.cid or b.country2 = co.cid group by co.name order by co.name Übung 1: SQL

  9. Übungsblatt 1 Erstellen Sie ein Abfrage, die folgende Informationen liefert: • Namen der Länder, Namen ihrer Hauptstädte, Einwohnerzahl des Landes, Einwohnerzahl der Hauptstadt, Anteil der Bevölkerung der Hauptstadt an der Gesamtbevölkerung in %, sortiert nach Namen der Länder • select co.name, ci.name, co.population, ci.population, ceil((ci.population / co.population) * 100) as CapPopPerc from country co, city ci where ci.name = co.capital and co.cid = ci.cid order by co.name Übung 1: SQL

  10. Übungsblatt 1 Erstellen Sie ein Abfrage, die folgende Informationen liefert: • Namen der Länder, Anzahl der Städte im Land, Einwohnerzahl des Landes, Einwohnerzahl der Städte zusammen, Anteil der Bevölkerung der Städte an der Gesamtbevölkerung des Landes in %, sortiert nach Namen der Länder • select co.name, count(ci.name), co.population, sum(ci.population), ceil((sum(ci.population) / co.population) * 100) from country co, city ci where co.cid = ci.cid group by co.name, co.population order by co.name Übung 1: SQL

  11. Übungsblatt 1 Erstellen Sie ein Abfrage, die folgende Informationen liefert: • Namen der Länder, Anzahl der Städte im Land, Einwohnerzahl des Landes, Einwohnerzahl der Städte, Anteil der Bevölkerung der Städte an der Gesamtbevölkerung des Landes in %, aber nur für verstädterte Länder (Anteil der Stadt- an der Gesamtbevölkerung >= 50%), sortiert nach Namen der Länder • select co.name, count(ci.name), co.population, sum(ci.population), ceil((sum(ci.population) / co.population) * 100) from country co, city ci where co.cid = ci.cid group by co.name, co.population having (ceil((sum(ci.population) / co.population) * 100) >= 50 and count(ci.name) > 1) order by co.name Übung 1: SQL

  12. Übungsblatt 1 Erstellen Sie ein Abfrage, die folgende Informationen liefert: • Namen der Länder, Namen der Nachbarländer mit gleicher Regierungsform, Regierungsform beider Länder, sofern das Land ein Nachbarland mit gleicher Regierungsform hat, sortiert nach Namen der Länder und darin nach Namen der Nachbarländer • select c1.name, c2.name, c2.government from country c1, country c2, borders b where ((b.country1 = c1.cid and b.country2 = c2.cid) or (b.country2 = c1.cid and b.country1 = c2.cid)) and (c1.government = c2.government) order by c1.name, c2.name Übung 1: SQL

  13. Übungsblatt 1 Erstellen Sie ein Abfrage, die folgende Informationen liefert: • Namen der Flüsse, ihre Länge, Fluß in den sie münden, dessen Länge, sofern der Fluß in einen anderen mündet, der kürzer ist als er selbst, sortiert nach Namen der Flüsse • select r1.name, r1.length, r2.name, r2.length from river r1, river r2 where r1.river is not null and r1.river = r2.name and r2.length < r1.length order by r2.name Übung 1: SQL

More Related