Auto commit
This commit is contained in:
parent
0ed3a59e2c
commit
947c7e78d2
@ -297,6 +297,30 @@ SELECT calculate_total_salary_by_job(1);
|
||||
|
||||
创建一个存储函数 `is_high_salary_department`,接受部门 ID 作为参数,返回一个布尔值(1 或 0)。如果该部门的平均工资大于等于 70000,返回 1(高薪部门),否则返回 0(非高薪部门)。
|
||||
|
||||
```sql
|
||||
DELIMITER $$
|
||||
DROP FUNCTION IF EXISTS is_high_salary_department;
|
||||
CREATE FUNCTION is_high_salary_department(dept_id INT)
|
||||
RETURNS INT
|
||||
DETERMINISTIC
|
||||
BEGIN
|
||||
IF(
|
||||
SELECT AVG(e.salary)
|
||||
FROM employee e
|
||||
WHERE e.dept_id = dept_id
|
||||
) > 70000 THEN
|
||||
RETURN 1;
|
||||
ELSE
|
||||
RETURN 0;
|
||||
END IF;
|
||||
END $$
|
||||
DELIMITER ;
|
||||
|
||||
SELECT is_high_salary_department(1);
|
||||
```
|
||||
|
||||
|
||||
|
||||
#### 练习题 10: 计算员工的总收入
|
||||
|
||||
创建一个存储函数 `calculate_total_income`,接受员工的工资和奖金(假设奖金为工资的 10%)作为参数,返回其总收入(工资 + 奖金)。
|
Loading…
x
Reference in New Issue
Block a user