Auto commit
This commit is contained in:
parent
49853d7338
commit
d9e06991e9
@ -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作为参数,返回该部门所有员工的工资总和。
|
||||
|
Loading…
x
Reference in New Issue
Block a user