This document contains 17 SQL queries that retrieve and analyze data from employee and department tables. The queries include selecting all records from a table, filtering records by name, ranking records by salary within department, extracting date parts and calculating periods, aggregating data by department and calculating totals, counting records by year, filtering by location count, finding unmatched departments, joining tables, paging with row numbers, filtering by manager, finding minimum records, applying conditional logic, grouping and aggregating minimum and maximum salaries, filtering by maximum of another query, and filtering by average of department.
This document contains 17 SQL queries that retrieve and analyze data from employee and department tables. The queries include selecting all records from a table, filtering records by name, ranking records by salary within department, extracting date parts and calculating periods, aggregating data by department and calculating totals, counting records by year, filtering by location count, finding unmatched departments, joining tables, paging with row numbers, filtering by manager, finding minimum records, applying conditional logic, grouping and aggregating minimum and maximum salaries, filtering by maximum of another query, and filtering by average of department.
This document contains 17 SQL queries that retrieve and analyze data from employee and department tables. The queries include selecting all records from a table, filtering records by name, ranking records by salary within department, extracting date parts and calculating periods, aggregating data by department and calculating totals, counting records by year, filtering by location count, finding unmatched departments, joining tables, paging with row numbers, filtering by manager, finding minimum records, applying conditional logic, grouping and aggregating minimum and maximum salaries, filtering by maximum of another query, and filtering by average of department.
FROM employees WHERE last_name LIKE 'A%'; 3- SELECT department, @row_number := CASE WHEN @department = department THEN @row_number + 1 ELSE 1 END AS department_rank, first_name, last_name, salary, @department := department FROM employees JOIN (SELECT @row_number := 0, @department := '') AS t ORDER BY department DESC, salary DESC; 4- SELECT last_name, first_name, hire_date, EXTRACT(YEAR FROM hire_date) AS year, CEILING(EXTRACT(MONTH FROM hire_date) / 6) AS semester, CEILING(EXTRACT(MONTH FROM hire_date) / 3) AS quarter FROM employes ORDER BY year DESC;
30.4) AS total_months FROM employees JOIN departments ON employees.department = departments.department_id GROUP BY departments.department_name; 6- SELECT departments.department_name, SUM(salary) AS total_salary FROM employees JOIN departments ON employees.department = departments.department_id GROUP BY departments.department_name; 7- SELECT COUNT(*) FROM employees WHERE year(hire_date) = 2000; 8- SELECT locations.location_id, COUNT(*) AS department_count FROM departments JOIN locations ON departments.location = locations.location_id GROUP BY locations.location_id HAVING COUNT(*) > 2; 9- SELECT department_name FROM departments WHERE department_id NOT IN ( SELECT department FROM employees ); 10- 1. SELECT employees.first_name, employees.last_name, jobs.job_title FROM employees JOIN jobs ON employees.job_id = jobs.job_id; 2. SELECT first_name, last_name, ( SELECT job_title FROM jobs WHERE employees.job_id = jobs.job_id ) AS job_title FROM employees; 11- SELECT ROW_NUMBER() OVER (ORDER BY departments.department_name) AS row_number, departments.department_name, countries.country_name, regions.region_name FROM departments JOIN countries ON departments.country = countries.country_id JOIN regions ON countries.region_id = regions.region_id ORDER BY departments.department_name; 12- SELECT first_name, last_name, email, phone_number, hire_date FROM employees WHERE manager_id = ( SELECT manager_id FROM employees WHERE last_name = 'Jones' ); 13- SELECT first_name, last_name, email, phone_number, hire_date, salary FROM employees WHERE salary = (SELECT MIN(salary) FROM employees); 14- SELECT first_name, last_name, CASE WHEN hire_date LIKE '%1998%' THEN 'NEEDS REVIEW' ELSE 'NOT THIS YEAR' END AS REVIEW FROM employees; 15- SELECT d.department_name, MIN(e.salary) AS min_salary, MAX(e.salary) AS max_salary FROM departments d LEFT JOIN employees e ON d.department_id = e.department_id GROUP BY d.department_name; 16- SELECT last_name, first_name, salary FROM employes WHERE salary > (SELECT MAX(salary) FROM employes WHERE job_id = 'SA_MAN'); 17- SELECT last_name, first_name, salary FROM employes e WHERE salary < (SELECT AVG(salary) FROM employes WHERE department_id = e.department_id); A.A.R