Auto commit
This commit is contained in:
parent
eb6a1ba10c
commit
6b086283b9
@ -134,6 +134,22 @@ SELECT calculate_annual_salary(3000);
|
||||
|
||||
创建一个存储函数 `calculate_years_of_service`,接受员工的入职日期作为参数,返回该员工的工龄(以年为单位)。
|
||||
|
||||
```sql
|
||||
DELIMITER $$
|
||||
DROP FUNCTION IF EXISTS calculate_years_of_service;
|
||||
CREATE FUNCTION calculate_years_of_service(hire_date DATE)
|
||||
RETURNS INT
|
||||
DETERMINISTIC
|
||||
BEGIN
|
||||
RETURN TIMESTAMPDIFF(YEAR,hire_date,NOW());
|
||||
END $$
|
||||
DELIMITER ;
|
||||
|
||||
SELECT calculate_years_of_service('2023-12-31');
|
||||
```
|
||||
|
||||
|
||||
|
||||
#### 练习题 3: 根据部门计算平均工资
|
||||
|
||||
创建一个存储函数 `calculate_avg_salary_by_dept`,接受部门 ID 作为参数,返回该部门的平均工资。
|
||||
|
Loading…
x
Reference in New Issue
Block a user