Auto commit
This commit is contained in:
parent
8fa209f213
commit
da1fcd8e75
@ -438,19 +438,92 @@ CALL get_employee_salary_rank(2);
|
||||
|
||||
创建一个存储过程 `get_department_total_salary`,接受部门ID作为参数,返回该部门所有员工的工资总和。
|
||||
|
||||
```sql
|
||||
DELIMITER $$
|
||||
DROP PROCEDURE IF EXISTS get_department_total_salary;
|
||||
CREATE PROCEDURE get_department_total_salary(IN id INT)
|
||||
BEGIN
|
||||
SELECT SUM(e.salary)
|
||||
FROM employee e
|
||||
WHERE e.dept_id = id;
|
||||
END $$
|
||||
DELIMITER ;
|
||||
CALL get_department_total_salary(1);
|
||||
```
|
||||
|
||||
|
||||
|
||||
#### 练习题 17: 查询职位工资总和
|
||||
|
||||
创建一个存储过程 `get_job_total_salary`,接受职位ID作为参数,返回该职位所有员工的工资总和。
|
||||
|
||||
```sql
|
||||
DELIMITER $$
|
||||
DROP PROCEDURE IF EXISTS get_job_total_salary;
|
||||
CREATE PROCEDURE get_job_total_salary(IN id INT)
|
||||
BEGIN
|
||||
SELECT SUM(e.salary)
|
||||
FROM employee e
|
||||
WHERE e.job_id = id;
|
||||
END $$
|
||||
DELIMITER ;
|
||||
CALL get_job_total_salary(1);
|
||||
```
|
||||
|
||||
|
||||
|
||||
#### 练习题 18: 查询员工入职年份分布
|
||||
|
||||
创建一个存储过程 `get_employees_by_hire_year`,接受年份作为参数,返回该年份入职的所有员工。
|
||||
|
||||
```sql
|
||||
DELIMITER $$
|
||||
DROP PROCEDURE IF EXISTS get_employees_by_hire_year;
|
||||
CREATE PROCEDURE get_employees_by_hire_year(IN y INT)
|
||||
BEGIN
|
||||
SELECT *
|
||||
FROM employee e
|
||||
WHERE YEAR(e.hire_date) = y;
|
||||
END $$
|
||||
DELIMITER ;
|
||||
CALL get_employees_by_hire_year(2020);
|
||||
```
|
||||
|
||||
|
||||
|
||||
#### 练习题 19: 查询部门工资分布
|
||||
|
||||
创建一个存储过程 `get_department_salary_distribution`,接受部门ID作为参数,返回该部门工资的分布情况(如最高、最低、平均工资)。
|
||||
|
||||
```sql
|
||||
DELIMITER $$
|
||||
DROP PROCEDURE IF EXISTS get_department_salary_distribution;
|
||||
CREATE PROCEDURE get_department_salary_distribution(IN id INT)
|
||||
BEGIN
|
||||
SELECT MAX(e.salary), MIN(e.salary), AVG(e.salary)
|
||||
FROM employee e
|
||||
WHERE e.dept_id = id;
|
||||
END $$
|
||||
DELIMITER ;
|
||||
CALL get_department_salary_distribution(1);
|
||||
```
|
||||
|
||||
|
||||
|
||||
#### 练习题 20: 查询职位工资分布
|
||||
|
||||
创建一个存储过程 `get_job_salary_distribution`,接受职位ID作为参数,返回该职位工资的分布情况(如最高、最低、平均工资)。
|
||||
|
||||
```sql
|
||||
DELIMITER $$
|
||||
DROP PROCEDURE IF EXISTS get_job_salary_distribution;
|
||||
CREATE PROCEDURE get_job_salary_distribution(IN id INT)
|
||||
BEGIN
|
||||
SELECT MAX(e.salary), MIN(e.salary), AVG(e.salary)
|
||||
FROM employee e
|
||||
WHERE e.job_id = id;
|
||||
END $$
|
||||
DELIMITER ;
|
||||
CALL get_job_salary_distribution(1);
|
||||
```
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user