Auto commit

This commit is contained in:
smallkun 2025-03-20 16:45:10 +08:00
parent 7e85346487
commit a192d96e71

View File

@ -281,10 +281,40 @@ CALL calculate_avg_salary_by_job(1);
创建一个存储过程 `get_high_salary_employees`,接受一个工资阈值作为参数,返回所有工资高于该阈值的员工。
```sql
DELIMITER $$
DROP PROCEDURE IF EXISTS get_high_salary_employees;
CREATE PROCEDURE get_high_salary_employees(IN sal DECIMAL(10, 2))
BEGIN
SELECT e.*
FROM employee e
WHERE e.salary > sal;
END $$
DELIMITER ;
CALL get_high_salary_employees(50000);
```
#### 练习题 9: 查询员工工龄
创建一个存储过程 `get_employee_years_of_service`接受员工ID作为参数返回该员工的工龄以年为单位
```sql
DELIMITER $$
DROP PROCEDURE IF EXISTS get_employee_years_of_service;
CREATE PROCEDURE get_employee_years_of_service(IN id INT)
BEGIN
SELECT -TIMESTAMPDIFF(YEAR,NOW(),e.hire_date)
FROM employee e
WHERE e.emp_id = id;
END $$
DELIMITER ;
CALL get_employee_years_of_service(1);
```
#### 练习题 10: 查询部门员工总数
创建一个存储过程 `get_department_employee_count`接受部门ID作为参数返回该部门的员工总数。