Auto commit
This commit is contained in:
parent
6b086283b9
commit
57e8628eec
@ -154,6 +154,25 @@ SELECT calculate_years_of_service('2023-12-31');
|
||||
|
||||
创建一个存储函数 `calculate_avg_salary_by_dept`,接受部门 ID 作为参数,返回该部门的平均工资。
|
||||
|
||||
```sql
|
||||
DELIMITER $$
|
||||
DROP FUNCTION IF EXISTS calculate_avg_salary_by_dept;
|
||||
CREATE FUNCTION calculate_avg_salary_by_dept(deptId INT)
|
||||
RETURNS DECIMAL(10,2)
|
||||
DETERMINISTIC
|
||||
BEGIN
|
||||
RETURN (
|
||||
SELECT AVG(salary)
|
||||
FROM employee e
|
||||
WHERE e.dept_id = deptId
|
||||
);
|
||||
END $$
|
||||
DELIMITER ;
|
||||
SELECT calculate_avg_salary_by_dept(1);
|
||||
```
|
||||
|
||||
|
||||
|
||||
#### 练习题 4: 根据职位计算平均工资
|
||||
|
||||
创建一个存储函数 `calculate_avg_salary_by_job`,接受职位 ID 作为参数,返回该职位的平均工资。
|
||||
|
Loading…
x
Reference in New Issue
Block a user