使用 UNION 和 INTERSECT 的查询

用 SQL 进行数据驱动决策

Tim Verdonck

Professor Statistics and Data Science

UNION

用 SQL 进行数据驱动决策

示例 - 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';
用 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          |
用 SQL 进行数据驱动决策

INTERSECT

用 SQL 进行数据驱动决策

示例 - 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          |
用 SQL 进行数据驱动决策

让我们练习!

用 SQL 进行数据驱动决策

Preparing Video For Download...