
考虑如下员工数据库,下划线为主键:
employee (person-name, street, city)
works (person-name, company-name, salary)
company (company-name, city)
manages (person-name, manager-name)
完成以下的操作:
1. 查询所有为First Bank Corporation工作的员工的姓名和居住城市;
2. 查询所有为First Bank Corporation工作且薪水超过1万元的员工姓
名、居住街道和城市;
3. 查询所有不为First Bank Corporation工作的员工;
4. 查询数据库中所有居住城市和其公司所在城市相同的员工;
5. 查询数据库中所有居住街道和城市与其经理相同的员工。
6. 查询数据库中工资比Small Bank Corporation的每个员工都高的所有
员工;
7. 假设一个公司可以在好几个城市有分部。找出位于Small Bank
Corporation所有所在城市的所有公司;
8. 找出雇员最多的公司;
9. 找出平均工资高于Small Bank Corporation平均工资的所有公司;
10. 修改数据库使Jones居住在Newton市;
11. 为Small Bank Corporation所有工资不超过1万美元的经理增加10%
的工资,对工资超出1万美元的只增加3%;
12. 删除Small Bank Corporation员工在works关系中的所有元组;
13. 为First Bank Corporation增加一个新的员工Tom,请加入必要的信
息。
14. 创建一个视图,包含如下信息:员工姓名,居住城市,所在公司名
称,公司所在城市,及其领导的姓名。
employee (person-name, street, city)
works (person-name, company-name, salary)
company (company-name, city)
manages (person-name, manager-name)
1. 查询所有为First Bank Corporation工作的员工的姓名和居住城市;
lect e.person-name
,
from works w,employee e
where company-name = ’First Bank Corporation’
and e. e.person-name=w. person-name
2. 查询所有为First Bank Corporation工作且薪水超过1万元的员工姓
名、居住街道和城市;
lect e. person-name, street, city
from employee e, works w
where y-name = ’First Bank Corporation’ and
w. person-name = e. person-nameand salary>10000
3. 查询所有不为First Bank Corporation工作的员工;
lect person-name
from employee
where person-name not in
(lect person-name
from works
where company-name = ’First Bank Corporation’)
4. 查询数据库中所有居住城市和其公司所在城市相同的员工;
lect e. person-name
from employee e, works w, company c
where e. person-name = w. person-name and = and
y -name = y -name
5. 查询数据库中所有居住街道和城市与其经理相同的员工;
lect P. person-name
from employee P, employee R, manages M
where P. person-name = M. person-name and
r-name = R. person-name and
= and =
6. 查询数据库中工资比Small Bank Corporation的每个员工都高的所有
员工;
lect person-name
from works
where salary all
>
(lect salary
from works
where company-name = ’Small Bank Corporation’)
7. 假设一个公司可以在好几个城市有分部。找出位于Small Bank
Corporation所有所在城市的所有公司;
lect y-name
from company S
where not exists (
(lect city
from company
where company-name = ’Small Bank Corporation’)
except
(lect city
from company T
where y-name = y-name))
8. 找出雇员最多的公司;
lect company-name
from works
group by company-name
having count (distinct person-name) >= all
(lect count (distinct person-name)
from works
group by company-name)
9. 找出平均工资高于Small Bank Corporation平均工资的所有公司;
lect company-name
from works
group by company-name
having avg (salary) >(lect avg (salary)
from works
where company-name = ’ Small Bank Corporation’)
10. 修改数据库使Jones居住在Newton市;
update employee
t city = ’Newton’
where person-name = ’Jones’
11. 为Small Bank Corporation所有工资不超过1万美元的经理增加10%
的工资,对工资超出1万美元的只增加3%;
update works T
t = * 1.03
where -name in (lect manager-name
from manages)
and * 1.1 > 100000
and y-name = ’ Small Bank Corporation’
update works T
t = * 1.1
where -name in (lect manager-name
from manages)
and * 1.1 <= 100000
and y-name = ’ Small Bank Corporation’
12. 删除Small Bank Corporation员工在works关系中的所有元组。
delete from works
where company-name = ’Small Bank Corporation’
13. 为First Bank Corporation增加一个新的员工Tom,请加入必要的信
息。
Inrt into person
Inrt into works
Inrt into manages
14. 创建一个视图,包含如下信息:员工姓名,居住城市,所在公司名
称,公司所在城市,及其领导的姓名。
Create view emp_info (name ,city ,company_name , company_city,
manager_name)
As
Select _name,, y-name,,r-name
From employee e, works w, company c, manages m
Where -name=-name
and y-name=y-name
and -name=-name

本文发布于:2023-11-24 11:52:32,感谢您对本站的认可!
本文链接:https://www.wtabcd.cn/zhishi/a/1700797952100210.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文word下载地址:SQL练习及答案.doc
本文 PDF 下载地址:SQL练习及答案.pdf
| 留言与评论(共有 0 条评论) |