简答题

    使用下面sql语句创建yggl(员工管理)数据库、employees表(员工表)、departments(部门表)、salary表(工资表)。set foreign_key_checks=0;drop database if exists yggl;create database yggl;use yggl;create table employees(eid char(6) primary key not null comment '员工编号',ename char(10) not null comment '姓名',education char(4) not null comment '学历' ,birthday date not null comment '出生日期',sex enum('男','女') not null default '男',workyear tinyint(1) comment '工作时间',did char(3) not null comment '员工部门编号',constraint fk_did foreign key (did) references departments(did));create table departments(did char(3) primary key comment '部门编号',dname char(20) not null comment '部门名称');create table salary(eid char(6) primary key comment '员工编号',income decimal(10,2) not null comment '收入',outcome decimal(10,2) not null comment '支出');insert into employees values ('001','wanlin','大专','1966-1-23','男','8','2'), ('002','ronghua','本科','1976-3-28','男','3','1'), ('003','xiangrong','硕士','1982-12-9','男','2','1'), ('004','lili','大专','1960-7-30','女','6','1'), ('005','liuming','本科','1972-10-18','男','3','5'), ('006','zhujun','硕士','1965-9-28','男','2','5'), ('007','zhongmin','硕士','1979-8-10','女','4','3'), ('008','shibing','本科','1974-10-1','男','1','5'), ('009','lintao','大专','1977-4-2','男','2','3'), ('010','yumin','本科','1968-9-20','男','3','4'), ('011','yefan','本科','1978-11-18','男','2','4'), ('012','linlin','大专','1969-9-3','女','5','4');insert into departments values ('1','财务部'), ('2','人力资源部'), ('3','经理办公室'), ('4','研发部'), ('5','市场部');insert into salary values ('001',2100.80,123.09), ('002',1528.62,88.03), ('003',2569.88,185.65), ('004',1987.01,79.58), ('005',2066.15,108.00), ('006',2980.70,210.20), ('007',3259.98,281.52), ('008',2860.00,198.00), ('009',2347.68,180.00), ('010',2531.98,199.08), ('011',2240.00,121.00), ('012',1980.00,100.00);在数据库yggl中,按下面要求创建存储过程:1.创建不带参数的存储过程count_sp(),统计1978-1-1之前出生的员工人数。2.创建带一个输入参数的存储过程realsalary_sp(),能根据员工编号eid,查询该员工的实际收入(即income-outcome值)。3.创建带一个输入参数的存储过程name_sp(),根据员工编号eid,查询该员工的姓名。4.创建一个存储过程education_sp(),用参数指定的员工学历education,查询具有该学历的所有员工。5.创建一个存储过程income_avg_sp(),用参数指定的部门名称dname,查询该部门所有员工的平均收入(即income平均值)。6.在employees员工表上创建存储过程emp_info_sp()。该存储过程的输入参数是type,输出参数是info。当type值是1时,计算employees员工表中男员工人数,然后通过参数info输出该人数;当type值是2时,计算employees员工表中女员工人数,然后通过参数info输出该人数;当type值为1和2以外的任何值时,将输出“类型错误!”。7.创建带一个输入参数的存储过程addincome_sp(),用参数指定的员工编号eid,修改该员工的income值。以员工workyear工作时间4年为基准,工作时间每增加1年,则收入income增加20(假如某员工workyear工作时间为9,则income增加20*(9-4)),如果员工workyear工作时间小于或等于4年则income值无变化。


    火星搜题