Abfragen mit UNION und INTERSECT

Datengestützte Entscheidungsfindung in SQL

Tim Verdonck

Professor Statistics and Data Science

UNION

Datengestützte Entscheidungsfindung in SQL

Beispiel – UNION

SELECT title, 
       genre, 
       renting_price
FROM movies
WHERE renting_price > 2.8
UNION
SELECT title, 
       genre, 
       renting_price
FROM movies
WHERE genre = 'Action & Adventure';
Datengestützte Entscheidungsfindung in SQL
SELECT title, 
       genre, 
       renting_price
FROM movies
WHERE renting_price > 2.8
UNION
SELECT title, 
       genre, 
       renting_price
FROM movies
WHERE genre = 'Action & Adventure';
| title      | genre              | renting_price |
|------------|--------------------|---------------|
|Fool's Gold | Action & Adventure | 2.69          |
|Astro Boy   | Action & Adventure | 2.89          |
|Fair Game   | Drama              | 2.89          |
Datengestützte Entscheidungsfindung in SQL

INTERSECT

Datengestützte Entscheidungsfindung in SQL

Beispiel – INTERSECT

SELECT title, 
       genre, 
       renting_price
FROM movies
WHERE renting_price > 2.8
INTERSECT
SELECT title, 
       genre, 
       renting_price
FROM movies
WHERE genre = 'Action & Adventure';
| title     | genre              | renting_price |
|-----------|--------------------|---------------|
| Astro Boy | Action & Adventure | 2.89          |
Datengestützte Entscheidungsfindung in SQL

Lass uns üben!

Datengestützte Entscheidungsfindung in SQL

Preparing Video For Download...