Práctica 7
Práctica 7
Práctica 7
7.2
Create a report that displays the employee number, last name, and salary of all employees who earn more than the average salary. Sort the results in order of ascending salary. SELECT employee_id, last_name, salary FROM employees WHERE salary > (SELECT AVG(salary) FROM employees) ORDER BY salary;
7.3
Write a query that displays the employee number and last name of all employees who work in a department with any employee whose last name contains a u. Save your SQL statement as lab_07_03.sql. Run your query. SELECT employee_id, last_name FROM employees WHERE department_id IN (SELECT department_id FROM employees WHERE last_name like '%u%');
7.4
The HR department needs a report that displays the last name, department number, and job ID of all employees whose department location ID is 1700 SELECT last_name, department_id, job_id FROM employees WHERE department_id IN (SELECT department_id FROM departments WHERE location_id = 1700);
Modify the query so that the user is prompted for a location ID. Save this to a file named lab_07_04.sql
SELECT last_name, department_id, job_id FROM employees WHERE department_id IN (SELECT department_id FROM departments WHERE location_id = &Enter_location);
7.5
Create a report for HR that displays the last name and salary of every employee who reports to King.
SELECT last_name, salary FROM employees WHERE employee_id = (SELECT employee_id FROM employees WHERE last_name = 'King');
SELECT last_name, salary FROM employees WHERE manager_id = 100; SELECT last_name, salary FROM employees WHERE manager_id = 156;
7.6
Create a report for HR that displays the department number, last name, and job ID for every employee in the Executive department. SELECT department_id, last_name, job_id FROM employees WHERE department_id IN (SELECT department_id FROM departments WHERE department_name = 'Executive');
7.7
Modify the query in lab_07_03.sql to display the employee number, last name, and salary of all employees who earn more than the average salary and who work in a department with any employee whose last name contains a u. Resave lab_07_03.sql to lab_07_07.sql. Run the statement in lab_07_07.sql. SELECT employee_id, last_name, salary FROM employees WHERE department_id IN (SELECT department_id FROM employees WHERE last_name like '%u%') AND salary > (SELECT AVG(salary) FROM employees);