From d9e06991e978670d0b7d131d7827c1736167c857 Mon Sep 17 00:00:00 2001 From: smallkun Date: Thu, 20 Mar 2025 16:31:34 +0800 Subject: [PATCH] Auto commit --- 2208/存储过程练习题.md | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/2208/存储过程练习题.md b/2208/存储过程练习题.md index 14b127e..ed0b804 100644 --- a/2208/存储过程练习题.md +++ b/2208/存储过程练习题.md @@ -219,6 +219,26 @@ CALL add_employee('李泽龙', 6666, '2025-3-20', 1, 1); 创建一个存储过程 `get_employee_salary_rank`,接受员工ID作为参数,返回该员工在公司中的工资排名。 +```sql +DELIMITER $$ +DROP PROCEDURE IF EXISTS get_employee_salary_rank; +CREATE PROCEDURE get_employee_salary_rank(IN emp_id INT) +BEGIN + SELECT COUNT(*) + 1 + FROM employee e + WHERE e.salary > ( + SELECT e.salary + FROM employee e + WHERE e.emp_id = emp_id + ); +END $$ +DELIMITER ; + +CALL get_employee_salary_rank(2); +``` + + + #### 练习题 16: 查询部门工资总和 创建一个存储过程 `get_department_total_salary`,接受部门ID作为参数,返回该部门所有员工的工资总和。