File tree 1 file changed +33
-0
lines changed 1 file changed +33
-0
lines changed Original file line number Diff line number Diff line change @@ -60,3 +60,36 @@ SELECT
60
60
first_name,
61
61
max_raise(employee_id)
62
62
FROM employees;
63
+
64
+ -- max_raise_2 function
65
+ CREATE OR REPLACE FUNCTION max_raise_2 (empl_id INT )
66
+ RETURNS NUMERIC (8 ,2 ) AS $$
67
+ DECLARE
68
+ employee_job_id INT ;
69
+ current_salary NUMERIC (8 ,2 );
70
+ job_max_salary NUMERIC (8 ,2 );
71
+ possible_raise NUMERIC (8 ,2 );
72
+ BEGIN
73
+ -- Take the job position and the salary
74
+ SELECT job_id, salary INTO employee_job_id, current_salary
75
+ FROM employees
76
+ WHERE employee_id = empl_id;
77
+
78
+ -- Take the max salary based on his job position
79
+ SELECT max_salary INTO job_max_salary
80
+ FROM jobs
81
+ WHERE job_id = employee_job_id;
82
+
83
+ -- Calculations
84
+ possible_raise = job_max_salary - current_salary;
85
+
86
+ RETURN possible_raise;
87
+ END;
88
+ $$ LANGUAGE plpgsql;
89
+
90
+ SELECT *
91
+ FROM max_raise_2(206 );
92
+
93
+ SELECT *
94
+ FROM employees
95
+ WHERE employee_id = 206 ;
You can’t perform that action at this time.
0 commit comments