Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

PLEASE HELP ME! Practice 2: Restricting and Sorting Data The HR department needs

ID: 3880032 • Letter: P

Question

PLEASE HELP ME!

Practice 2: Restricting and Sorting Data The HR department needs your assistance in creating some queries. 1. Because of budget issues, the HR department needs a report that displays the last name and salary of employees earning more than $12,000. Save your SQL statement as a file named lab_02_01.sql. Run your query.

2. Open a new SQL Worksheet. Create a report that displays the last name and department number for employee number 176.

3. The HR departments needs to find employees with high salary and low salary. Modify lab_02_01.sql to display the last name and salary for all employees whose salary is not in the range of $5,000 to $12,000. Save your SQL statement as lab_02_03.sql.

4. Create a report to display the last name, job ID, and hire date for employees with the last names of Matos and Taylor. Order the query in ascending order by hire date.

5. Display the last name and department ID of all employees in departments 20 or 50 in ascending alphabetical order by name.

6. Modify lab_02_03.sql to list the last name and salary of employees who earn between $5,000 and $12,000, and are in department 20 or 50. Label the columns Employee and Monthly Salary, respectively. Resave lab_02_03.sql as lab_02_06.sql. Run the statement in lab_02_06.sql.

7. The HR department needs a report that displays the last name and hire date for all employees who were hired in 1994.

8. Create a report to display the last name and job title of all employees who do not have a manager.

9. Create a report to display the last name, salary, and commission for all employees who earn commissions. Sort data in descending order of salary and commissions. Use the column’s numeric position in the ORDER BY clause.

10. Members of the HR department want to have more flexibility with the queries that you are writing. They would like a report that displays the last name and salary of employees who earn more than an amount that the user specifies after a prompt. (You can use the query created in practice exercise 1 and modify it.) Save this query to a file named lab_02_10.sql. a. Enter 12000 when prompted for a value in a dialog box. Click OK

11. The HR department wants to run reports based on a manager. Create a query that prompts the user for a manager ID and generates the employee ID, last name, salary, and department for that manager’s employees. The HR department wants the ability to sort the report on a selected column. You can test the data with the following values: manager _id = 103, sorted by last_name manager_id = 201, sorted by salary manager_id = 124, sorted by employee_id If you have the time, complete the following exercises (Optional)

12. Display all employee last names in which the third letter of the name is “a.” SELECT last_name FROM employees WHERE last_name LIKE '__a%'; 13. Display the last names of all employees who have both an “a” and an “e” in their last name. SELECT last_name FROM employees WHERE last_name LIKE '%a%' AND last_name LIKE '%e%';

If you want an extra challenge, complete the following exercises: 14. Display the last name, job, and salary for all employees whose job is that of a sales representative or a stock clerk, and whose salary is not equal to $2,500, $3,500, or $7,000. SELECT last_name, job_id, salary FROM employees WHERE job_id IN ('SA_REP', 'ST_CLERK') AND salary NOT IN (2500, 3500, 7000); 15. Modify lab_02_06.sql to display the last name, salary, and commission for all employees whose commission amount is 20%. Resave lab_02_06.sql as lab_02_15.sql. Rerun the statement in lab_02_15.sql. SELECT last_name "Employee", salary "Monthly Salary", commission_pct FROM employees WHERE commission_pct = .20;

Explanation / Answer

First we have EMPLOYEES table. And table containing data.

CREATE TABLE `employees` (

`emp_id` int(11) NOT NULL,

`first_name` varchar(45) NOT NULL,

`last_name` varchar(45) NOT NULL,

`salary` double NOT NULL,

`department_id` varchar(45) NOT NULL,

`job_id` varchar(45) DEFAULT NULL,

`hire_date` date DEFAULT NULL,

`job_title` varchar(45) DEFAULT NULL,

`commission` double DEFAULT NULL,

PRIMARY KEY (`emp_id`)

) ENGINE=InnoDB DEFAULT CHARSET=utf8;

SELECT * FROM employees;

'1', 'Kamath', 'Jana reddy', '7000', '20', 'SW01', '1994-01-20', 'software engineer', '1'

'2', 'Vinay', 'akash', '8000', '25', 'FM01', '2017-02-20', 'finance manager', '2'

'3', 'Sai', 'Manoj', '12000', '50', 'SM001', '2017-06-01', 'sales manager', '5'

'4', 'Yugandhar', 'Matos', '16000', '20', 'MM01', '1994-04-16', 'marketing manager', '7'

'176', 'Hari', 'Taylor', '30000', '25', 'SW02', '2017-08-20', 'software engineer', '3'

1) SELECT last_name ,salary FROM employees where salary > 12000; --- lab_02_01.sql.

2) SELECT last_name ,department_i FROM employees where emp_id=176;

3) select max(salary) from employees;

select min(salary) from employees;

SELECT last_name ,salary FROM employees where salary not between 5000 and 12000;

4) SELECT last_name ,job_id ,hire_date FROM employees where last_name like "%Taylor%" order by hire_date ;

SELECT last_name ,job_id ,hire_date FROM employees where last_name like "%Matos%" order by hire_date ;

5) SELECT last_name ,department_id FROM employees where department_id = 20 or department_id = 50 order by last_name;

6) SELECT last_name ,salary,department_id FROM employees where salary between 5000 and 12000 and (department_id= 20 or department_id=50);

7) SELECT last_name ,hire_date FROM employees where year(hire_date) = 1994;

8) SELECT last_name ,job_title FROM employees where job_title not like '%manager%' ;

10) For getting dynamic data you should use procedures.

Here is the procedure which returns output according to input.

CREATE DEFINER=`root`@`localhost` PROCEDURE `getSalariesBasedonSelect`(in salary_in double)

BEGIN

SELECT last_name ,salary FROM employees where salary > salary_in;

END

  

12) SELECT last_name FROM employees WHERE last_name LIKE '__a%'

SELECT last_name FROM employees WHERE last_name LIKE '%a%' AND last_name LIKE '%e%';

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote