diff --git a/2208/存储过程练习题.md b/2208/存储过程练习题.md index 6e714f0..2d64d98 100644 --- a/2208/存储过程练习题.md +++ b/2208/存储过程练习题.md @@ -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作为参数,返回该部门的员工总数。