2024-07-12
한어Русский языкEnglishFrançaisIndonesianSanskrit日本語DeutschPortuguêsΕλληνικάespañolItalianoSuomalainenLatina
数据准备 创建两张表:部门(dept)和员工(emp),并插入数据,代码如下 create table dept( dept_id int primary key auto_increment comment '部门编号', dept_name char(20)comment'部门名称' ); insert into dept (dept_name) values('销售部'),('财务部'),('生产部'),('人事部'); create table emp( emp_id int primary key auto_increment comment'员工号', emp_name char(20)not null default '' comment '员工姓名', gender char(2)not null default '男' comment'性别', birth datetime not null default '1990-1-1' comment'出生日期', salary decimal(10,2)not null default 0 comment'工资', address varchar(200)not null default '' comment'通讯地址', dept_id int comment'部门编号' ); create index idx_name on emp(emp_name); create index idx_birth on emp (birth); create index idx_deptid_name on emp(dept id,emp_name); insert into emp(emp_name,gender ,birth ,salary, address,dept_id) values('张晓红', '女', '1980-01-23', 5800, '河南省郑州市中原路10号', 1), ('张静静', '女', '1987-10-03', 5400, '河南省新乡市平原路38号', 1), ('王云飞', '男', '1992-11-15', 5600, '河南省新乡市人民路28号', 1), ('王鹏飞', '男', '1987-10-01', 6800, '河南省新乡市东明大道12号', 1), ('王大鹏', '男', '1989-02-11', 5900, '河南省郑州市东风路15号', 1), ('王萌萌', '女', '1986-12-30', 5000, '河南省开封市五一路14号', 2), ('王大光', '男', '1988-11-08', 6200, '河南省开封市八一路124号', 2), ('王小明', '男', '1998-01-03', 4800, '河南省驻马店市雪松路128号', 2), ('王娜娜', '女', '1994-03-05', 5200, '河南省驻马店市车站路2号', 2), ('刘云飞', '男', '1992-08-13', 6800, '河南省南阳市民生路255号', 3), ('张陆军', '男', '1991-09-06', 6200, '河南省南阳市张仲景路14号', 3); 1、创建视图v_emp_dept_id_1,查询销售部门的员工姓名和家庭住址, 2、创建视图v_emp_dept,查询销售部门员工姓名和家庭住址及部门名称。 3、创建视图v_dept_emp_count(dept_name,emp count,avg salay),统计每个部门人数并计算平均工资 4、修改视图v_emp_dept,查询销售部门员工姓名、家庭住址、工资和部门名称。 5、查看视图名称; 查看视图结构; 查看创建视图语句; 6、删除以上三个视图。 存储过程作业: 1、创建一个提取emp表所有员工工资和的存储过程s1 2、调用存储过程s1 3、创建存储过程s2,实现输入员工姓名后返回员工的家庭住址, 4、调用存储过程s2 5、创建一个存储过程avg sai,有3个参数,分别是dept,gender,接收平均工资,功能査询emp表dep 6、调用存储过程avg sai 7、删除以上存储过程
1. Create a view v_emp_dept_id_1 to query the names and home addresses of employees in the sales department.
2. Create the view v_emp_dept to query the names, home addresses, and department names of the sales department employees.
3. Create a view v_dept_emp_count(dept_name,emp count,avg salay) to count the number of people in each department and calculate the average salary
4. Modify the view v_emp_dept to query the name, home address, salary and department name of the sales department employees.
5. Check the view name;
Check out the view structure;
Check the statement to create a view; (this part will have format errors when using the command line, so use visualization software to output)
6. Delete the above three views.
1. Create a stored procedure s1 to extract the salary and total of all employees in the emp table
2. Call stored procedure s1
3. Create a stored procedure s2 to return the employee's home address after entering the employee's name.
4. Call stored procedure s2
5. Create a stored procedure avg sai with three parameters, dept and gender, to receive the average salary and query the emp table dep
6. Call the stored procedure avg_sai
7. Delete the above stored procedures