Auto commit

This commit is contained in:
smallkun 2025-03-20 16:42:33 +08:00
parent a19a2490e0
commit 7e85346487

View File

@ -186,22 +186,97 @@ CALL update_employee_salary(1, 60000);
创建一个存储过程 `delete_employee`接受员工ID作为参数删除该员工的记录。
```sql
DELIMITER $$
DROP PROCEDURE IF EXISTS delete_employee;
CREATE PROCEDURE delete_employee(IN id INT)
BEGIN
DELETE FROM employee
WHERE emp_id = id;
END $$
DELIMITER ;
CALL delete_employee(1);
```
#### 练习题 4: 查询部门员工
创建一个存储过程 `get_department_employees`接受部门ID作为参数返回该部门所有员工的详细信息。
```sql
DELIMITER $$
DROP PROCEDURE IF EXISTS get_department_employees;
CREATE PROCEDURE get_department_employees(IN id INT)
BEGIN
SELECT e.*
FROM employee e
WHERE e.dept_id = id;
END $$
DELIMITER ;
CALL get_department_employees(1);
```
#### 练习题 5: 查询职位员工
创建一个存储过程 `get_job_employees`接受职位ID作为参数返回该职位所有员工的详细信息。
```sql
DELIMITER $$
DROP PROCEDURE IF EXISTS get_job_employees;
CREATE PROCEDURE get_job_employees(IN id INT)
BEGIN
SELECT e.*
FROM employee e
WHERE e.job_id = id;
END $$
DELIMITER ;
CALL get_job_employees(1);
```
#### 练习题 6: 计算部门平均工资
创建一个存储过程 `calculate_avg_salary_by_dept`接受部门ID作为参数返回该部门的平均工资。
```sql
DELIMITER $$
DROP PROCEDURE IF EXISTS calculate_avg_salary_by_dept;
CREATE PROCEDURE calculate_avg_salary_by_dept(IN id INT)
BEGIN
SELECT AVG(e.salary)
FROM employee e
WHERE e.dept_id = id;
END $$
DELIMITER ;
CALL calculate_avg_salary_by_dept(1);
```
#### 练习题 7: 计算职位平均工资
创建一个存储过程 `calculate_avg_salary_by_job`接受职位ID作为参数返回该职位的平均工资。
```sql
DELIMITER $$
DROP PROCEDURE IF EXISTS calculate_avg_salary_by_job;
CREATE PROCEDURE calculate_avg_salary_by_job(IN id INT)
BEGIN
SELECT AVG(e.salary)
FROM employee e
WHERE e.job_id = id;
END $$
DELIMITER ;
CALL calculate_avg_salary_by_job(1);
```
#### 练习题 8: 查询高薪员工
创建一个存储过程 `get_high_salary_employees`,接受一个工资阈值作为参数,返回所有工资高于该阈值的员工。