Employee Hiring and Salary Analysis
Employee Hiring and Salary Analysis
You employ a set operation (MINUS) to differentiate job roles in the current employees list from those in job history: SELECT last_name, job_id FROM employee WHERE job_id IN (SELECT job_id FROM employee MINUS SELECT job_id FROM job_history) ORDER BY last_name;
To list employees with unique job IDs, use: SELECT last_name, job_id FROM employee WHERE job_id IN (SELECT job_id FROM employee MINUS SELECT job_id FROM job_history) ORDER BY last_name;
Utilize this query: SELECT last_name, job_id, salary FROM employee WHERE salary < (SELECT AVG(salary) FROM employee WHERE department_id IN (SELECT department_id FROM department WHERE location_id IN (SELECT location_id FROM location WHERE city = 'Oxford'))) AND job_id NOT LIKE 'MK%' ORDER BY 3 DESC, 1;
Applying multiple subqueries without using JOINs addresses the problem. For instance: the conditions apply subquery to filter department_id by location and another for filtering the salary comparing with the average such as: SELECT last_name, job_id, salary FROM employee WHERE salary < (SELECT AVG(salary) FROM employee WHERE department_id IN (SELECT department_id FROM department WHERE location_id IN (SELECT location_id WHERE city = 'Oxford'))) AND job_id NOT LIKE 'MK%';
Apply filtering in the WHERE clause for both conditions: salary being outside the range (<8000 OR >14000) and hire_date being greater than or equal to the date (e.g., '1995-07-01') to restrict employees hired only after June 1995.
To achieve this, use the query: SELECT last_name AS "Lname", job_id AS "Job Title", to_char(hire_date, 'DAY', 'fmDdspth' of 'Month', 'YYYY') AS "Start Date", salary AS "Pay" FROM employee WHERE (salary < 8000 OR salary > 14000) AND (hire_date >= '95-07-01') ORDER BY 2, 4 DESC;
Use GROUP BY to group jobs and HAVING to set a condition on employee count, shown by: SELECT job_id AS "Position", COUNT(*) AS "# of People" FROM employee GROUP BY job_id HAVING (job_id LIKE 'IT%' OR job_id LIKE 'MK%' AND COUNT(*) > 2) ORDER BY 2 DESC;
The TO_CHAR function is well-suited for this purpose, specifically using a format string like 'DAY', 'fmDdspth' of 'Month', 'YYYY' to get an easily understandable format.
Use the TO_CHAR function in SQL with the format specified as: to_char(hire_date, 'DAY', 'fmDdspth' of 'Month', 'YYYY'). This formats the date into verbose English phrases.
The query to find job positions in IT and Marketing departments with more than two employees is: SELECT job_id AS "Postion", COUNT(*) AS "# of People" FROM employee GROUP BY job_id HAVING (job_id LIKE 'IT%' OR job_id LIKE 'MK%' AND COUNT(*) >= 2) ORDER BY 2 DESC;