搜题
问题   更新时间2023/4/3 12:59:00

关系模式Personal描述了职员的基本信息,属性pid, name, sex, photo, birthday, age, salary、dept、senior分别表示个人编号、姓名、性别、照片、出生日期、年龄、薪酬、部门、上司,其中照片字段、薪酬字段和上司字段允许为空,其他字段全部为非空,上司对应本表中的另一个人编号,其中性别限定只能输入’男’或’女’
关系模式Resume描述了职员任职信息,属性id, seq, startdate, enddate, job分别表示个人编号、序号、起始日期、终止日期、职位,每个人可以有多条记录,其中每人只允许最多有一条记录中的终止日期为空,其他字段全部为非空。请使用SQL语言实现下列功能:(1). 为上述两个模式建立数据库基表,包括建立关键字及约束条件;
(2). 查询所有现职男职员;
(3). 查询所有年龄为30岁以上且任职数为两个以上的所有人员的基本信息;
(4). 查询所有既有上司且又有下属的职员的基本信息,要求按照年龄升序、出生日期降序排列;
(5). 为所有2001年10月5日之前任职的女性职员增加工资10%。

解答: (1) create table Personal( pid int not null primary key, name varchar(20) not null, sex char(2) check(sex in('男','女')), photo varchar(20), birthday date not null, salary bigint, dept varchar(20) not null, senior int, FOREIGN KEY(senior) REFERENCES Personal(pid) ); create table Resume( id int not null, seq int not null, startdate date not null, enddate date, job varchar(30) not null CONSTRAINT C1 check(2>( select sum(enddate) from Resume where enddate=NULL) ) ); (2) select * from Personal where sex='男' (3) select * from Personal where(age>30 and Pid in(select id form Resume group by id having count(*)>2; ) ) (4) select * from Personal where(senior is not null and pid in( select senior from Personal ) ) order by age ASC,birthday DESC; (5) update Personal set salary=salary*1.1 where sex='女' and Pid in( select distinct id from Resume where startdate<'2001-10-05' )
王老师:19139051760(拨打)