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