Lesson 11 Payroll Calculation Solution
Lesson 11 Payroll Calculation Solution
Lesson 11 Payroll Calculation Solution
2. Write a query to insert values into the employee and department tables
SQL code:
CREATE VIEW emp AS SELECT f_name,l_name,salary ,dept_name,location,emp_id
FROM lep_7.employee,lep_7.department WHERE l_name = 'jain';
4. Write a query to display the first and last names of every employee in the employee
table whose salary is greater than the average salary of the employees listed in the
SQL basics table
SQL code:
SELECT e.f_name,e.l_name
FROM lep_7.employee e,sqlbasics.emp s
WHERE e.salary > s.salary;
Output:
5. Write a query to change the delimiter to //
SQL code:
delimiter //
6. Write a query to create a stored procedure in the employee table for every
employee whose salary is greater than or equal to 250,000
SQL code:
use lep_7;
SELECT * from employee;
delimiter &&
CREATE PROCEDURE top_salarys()
BEGIN
SELECT job_id,f_name,salary
FROM employee where salary>=250000;
END &&
delimiter ;;
7. Write a query to execute the stored procedure
SQL code:
call top_salarys();
Output:
8. Write a query to create and execute a stored procedure with one parameter using
the order by function in descending order of the salary earned
SQL code:
delimiter //
CREATE PROCEDURE sort_salarys(IN var INT)
BEGIN
SELECT job_id,f_name,salary
FROM employee ORDER BY salary DESC LIMIT var;
end //
delimiter ;
call sort_salarys(3);
Output: