Auto commit
This commit is contained in:
parent
eaa1811ce7
commit
ba7a5971be
@ -115,6 +115,11 @@ INSERT INTO employee (emp_name, salary, hire_date, dept_id, job_id) VALUES
|
||||
|
||||
创建一个存储函数 `calculate_annual_salary`,接受员工的月薪作为参数,返回其年薪(假设年薪为月薪的 12 倍)。
|
||||
|
||||
```c
|
||||
```
|
||||
|
||||
|
||||
|
||||
#### 练习题 2: 计算员工工龄
|
||||
|
||||
创建一个存储函数 `calculate_years_of_service`,接受员工的入职日期作为参数,返回该员工的工龄(以年为单位)。
|
||||
|
@ -177,10 +177,46 @@ SELECT calculate_avg_salary_by_dept(1);
|
||||
|
||||
创建一个存储函数 `calculate_avg_salary_by_job`,接受职位 ID 作为参数,返回该职位的平均工资。
|
||||
|
||||
```sql
|
||||
DELIMITER $$
|
||||
DROP FUNCTION IF EXISTS calculate_avg_salary_by_job;
|
||||
CREATE FUNCTION calculate_avg_salary_by_job(job_id INT)
|
||||
RETURNS INT
|
||||
DETERMINISTIC
|
||||
BEGIN
|
||||
RETURN (
|
||||
SELECT AVG(e.salary)
|
||||
FROM employee e
|
||||
WHERE e.job_id = job_id
|
||||
);
|
||||
END $$
|
||||
DELIMITER ;
|
||||
|
||||
SELECT calculate_avg_salary_by_job(1);
|
||||
```
|
||||
|
||||
|
||||
|
||||
#### 练习题 5: 计算员工税后工资
|
||||
|
||||
创建一个存储函数 `calculate_net_salary`,接受员工的工资作为参数,返回其税后工资(假设税率为 15%)。
|
||||
|
||||
```sql
|
||||
DELIMITER $$
|
||||
DROP FUNCTION IF EXISTS calculate_net_salary;
|
||||
CREATE FUNCTION calculate_net_salary(sal DECIMAL(10, 2))
|
||||
RETURNS DECIMAL(10, 2)
|
||||
DETERMINISTIC
|
||||
BEGIN
|
||||
RETURN sal*0.85;
|
||||
END $$
|
||||
DELIMITER ;
|
||||
|
||||
SELECT calculate_net_salary(3000);
|
||||
```
|
||||
|
||||
|
||||
|
||||
#### 练习题 6: 判断员工是否满足加薪条件
|
||||
|
||||
创建一个存储函数 `is_eligible_for_raise`,接受员工的工资和工龄作为参数,返回一个布尔值(1 或 0)。加薪条件如下:
|
||||
|
Loading…
x
Reference in New Issue
Block a user