75%(4)3 out of 4 people found this document helpful
This preview shows page 7 - 13 out of 17 pages.
0.01 secondsNext, again using the job ID given, select the average salary for all employees with that job id (use the ROUND function to round this average to 2 decimal places)….SELECT job_id, ROUND(AVG(salary), 2)
FROM employees join jobs using (job_id)WHERE job_id = 'ST_CLERK' GROUP BY job_id;JOB_IDROUND(AVG(SALARY),2)ST_CLERK27851 rows returned in 0.00 secondsDowDECLAREv_jobid employees.job_id%TYPE;V_rasal employees.salary%TYPE;BEGINSELECT job_id, ROUND(AVG(salary), 2)into v_jobid, v_rasalFROM employees WHERE job_id = 'ST_CLERK' GROUP BY job_id;DBMS_OUTPUT.PUT_LINE(v_rasal);END;2785Statement processed.
0.01 secondsI was expecting one and I got one.If the salary for the requested employee is less than the average for their job ID, display a message, indicating it’s less than the average, otherwise…..DECLAREv_jobid employees.job_id%TYPE;v_empid employees.employee_id%TYPE;v_empsal employees.salary%TYPE;V_rasal employees.salary%TYPE;BEGINSELECT job_id, employee_id, salary, ROUND(AVG(salary), 2)into v_jobid, v_empid, v_empsal, v_rasalFROM employeesWHERE job_id = 'ST_CLERK' AND employee_id = 125GROUP BY job_id, employee_id, salary;if v_rasal > v_empsal thenDBMS_OUTPUT.PUT_LINE('Employee Nayer has a salary of 3200 which is less than the Stock Clerk average of 2785');
elsif v_rasal < v_empsal thenDBMS_OUTPUT.PUT_LINE('Employee Nayer has a salary of 3200 which is equalto the Stock Clerk average of 2785');elseDBMS_OUTPUT.PUT_LINE('Employee Nayer has a salary of 3200 which is more than the Stock Clerk average of 2785');END IF;END;Employee Nayer has a salary of 3200 which is more than the Stock Clerk average of 2785Statement processed.0.01 secondsNow, change the value of your variable to ST_MAN and re-run your code. Try SH_CLERKDECLAREv_jobid employees.job_id%TYPE;v_empid employees.employee_id%TYPE;v_empsal employees.salary%TYPE;V_rasal employees.salary%TYPE;
BEGINSELECT job_id, employee_id, salary, ROUND(AVG(salary), 2)into v_jobid, v_empid, v_empsal, v_rasalFROM employeesWHERE job_id = 'ST_MAN' AND employee_id = 120GROUP BY job_id, employee_id, salary;if v_rasal > v_empsal thenDBMS_OUTPUT.PUT_LINE('Employee Weiss has a salary of 8000 which is less than the Stock Clerk average of 2785');elsif v_rasal = v_empsal thenDBMS_OUTPUT.PUT_LINE('Employee Weiss has a salary of 8000 which is equal to the Stock Clerk average of 2785');elseDBMS_OUTPUT.PUT_LINE('Employee Weiss has a salary of 8000 which is more than the Stock Clerk average of 2785');END IF;END;Employee Weiss has a salary of 8000 which is more than the Stock Clerk average of 2785Statement processed.
0.01 secondsDECLAREv_jobid employees.job_id%TYPE;v_empid employees.employee_id%TYPE;V_rasal NUMBER(8,2);v_empsal employees.salary%TYPE;BEGINSELECT salary into v_empsalFROM employees