admin管理员组文章数量:1558087
- 用JOINs进行多表联合查询
- 1.【联表】找到所有电影的国内Domestic_sales和国际销售额
- 2.【联表】找到所有国际销售额比国内销售大的电影
- 3.【联表】找出所有电影按市场占有率rating倒序排列
- 4.【联表】每部电影按国际销售额比较,排名最靠前的导演是谁,国际销量多少
- 外连接(OUTER JOINs)
- 【复习】找到所有有雇员的办公室(buildings)名字
- 2.【复习】找到所有办公室里的所有角色(包含没有雇员的),并做唯一输出(DISTINCT)
- 3. 【难题】找到所有有雇员的办公室(buildings)和对应的容量
- 关于特殊关键字 NULLs
- 题目
- 1.【复习】找到雇员里还没有分配办公室的(列出名字和角色就可以) ✓
- 2.【难题】找到还没有雇员的办公室
用JOINs进行多表联合查询
题目
1.【联表】找到所有电影的国内Domestic_sales和国际销售额
SELECT * FROM movies
join boxoffice
on movies.id=movie_id
2.【联表】找到所有国际销售额比国内销售大的电影
SELECT * FROM movies
join boxoffice
on movies.id=movie_id
where Domestic_sales<International_sales
3.【联表】找出所有电影按市场占有率rating倒序排列
SELECT * FROM movies
join boxoffice
on movies.id=movie_id
order by rating desc
4.【联表】每部电影按国际销售额比较,排名最靠前的导演是谁,国际销量多少
SELECT director , international_sales FROM movies
join boxoffice
on movies.id=movie_id
order by international_sales desc
limit 1;
外连接(OUTER JOINs)
题目
【复习】找到所有有雇员的办公室(buildings)名字
SELECT distinct Building_name from employees
left join buildings
on employees.Building=Buildings.Building_name
where Building
解析:保留employees 的全部信息,
2.【复习】找到所有办公室里的所有角色(包含没有雇员的),并做唯一输出(DISTINCT)
理解:不同办公室的工种
SELECT distinct role,Building_name from buildings
left join Employees
on buildings.Building_name=Employees.BUilding
3. 【难题】找到所有有雇员的办公室(buildings)和对应的容量
SELECT distinct Building_name ,capacity from
buildings
left join Employees
on Buildings.Building_name=employees.Building
where building
关于特殊关键字 NULLs
题目
1.【复习】找到雇员里还没有分配办公室的(列出名字和角色就可以) ✓
SELECT name, role FROM employees
where Building is null;
2.【难题】找到还没有雇员的办公室
SELECT distinct Building_name from buildings
left join employees
on employees.Building=Buildings.Building_name
where name is null;
版权声明:本文标题:多表联合查询—— 自学SQL网 6—8(资料,试题,答案) 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://m.elefans.com/dongtai/1727371947a1111281.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论