1. Klassische Postwurfsendung
Sie wollen alle Ihre Kunden mit einer gedruckten Werbebroschüre beglücken. Entwerfen Sie eine Abfrage, die folgende Felder ausgibt, die Sie für einen wohl adressierten Serienbrief benötigen:
- Vor- und Nachname
- Straßenanschrift
- Land
- Postleitzahl
- Wohnort
Adressen ohne Postleitzahl, sollen nicht ausgegeben werden. Das Porto können wir uns sparen, wenn die Post nicht weiß, wo der Ort liegt.
1 2 3 4 5 6 7 8 9 10 11 12 |
SELECT first_name , last_name , address , country , postal_code , city FROM customer c1 JOIN address a ON a.address_id = c1.address_id JOIN city c2 ON c2.city_id = a.city_id JOIN country c3 ON c3.country_id = c2.country_id WHERE postal_code IS NOT NULL; |
+----------+---------+-----------------------+-------------+-----------+--------------+ |first_name|last_name|address |country |postal_code|city | +----------+---------+-----------------------+-------------+-----------+--------------+ |Jared |Ely |1003 Qinhuangdao Street|Indonesia |25972 |Purwakarta | |Mary |Smith |1913 Hanoi Way |Japan |35200 |Sasebo | |Patricia |Johnson |1121 Loja Avenue |United States|17886 |San Bernardino| |Linda |Williams |692 Joliet Street |Greece |83579 |Athenai | |Barbara |Jones |1566 Inegl Manor |Myanmar |53561 |Myingyan | ... (599 Datensätze insgesamt)
2. Filme und Schauspieler
Erstellen Sie eine nach Filmtiteln sortierte Liste. Welche Schauspieler wirken jeweils mit. Geben Sie diese nach Nachnamen, Vornamen sortiert aus.
1 2 3 4 5 6 7 8 9 10 11 |
SELECT title , first_name , last_name FROM film fi JOIN film_actor fa ON fi.film_id = fa.film_id JOIN actor ac ON fa.actor_id = ac.actor_id ORDER BY title , last_name , first_name; |
+----------------+----------+---------+ |title |first_name|last_name| +----------------+----------+---------+ |Academy Dinosaur|Johnny |Cage | |Academy Dinosaur|Rock |Dukakis | |Academy Dinosaur|Christian |Gable | |Academy Dinosaur|Penelope |Guiness | |Academy Dinosaur|Mary |Keitel | |Academy Dinosaur|Oprah |Kilmer | |Academy Dinosaur|Warren |Nolte | |Academy Dinosaur|Sandra |Peck | |Academy Dinosaur|Mena |Temple | |Academy Dinosaur|Lucille |Tracy | |Ace Goldfinger |Chris |Depp | ... (5462 Datensätze insgesamt)
3. Fehlende Zuordnungen
Auf den ersten Blick werden Sie es nicht erkannt haben. In der Liste von Aufgabe 2 fehlen Filme. Ihnen ist kein Schauspieler zugeordnet. Welche Filme sind das?
1 2 3 4 5 |
SELECT title FROM film fi LEFT JOIN film_actor fa ON fi.film_id = fa.film_id WHERE fa.film_id IS NULL; |
+----------------+ |title | +----------------+ |Drumline Cyclone| |Flight Lies | |Slacker Liaisons| +----------------+