0% found this document useful (0 votes)
12 views3 pages

Employee Data Queries and Analysis

The document contains a series of SQL queries designed to extract various employee-related data from a database. It includes queries for listing employees, filtering by salary and department, joining with other tables for additional information, and performing aggregate functions. The queries cover a wide range of operations, such as sorting, grouping, and calculating totals and averages.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views3 pages

Employee Data Queries and Analysis

The document contains a series of SQL queries designed to extract various employee-related data from a database. It includes queries for listing employees, filtering by salary and department, joining with other tables for additional information, and performing aggregate functions. The queries cover a wide range of operations, such as sorting, grouping, and calculating totals and averages.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

--1. List the first name and last name of all employees.

SELECT first_name, last_name


FROM employees;

--2. Display the employee ID, name, and salary for employees earning more than
10,000.
SELECT employee_id, first_name, salary
FROM employees
WHERE salary > 10000;

--3. Find all employees who work in department 90.

SELECT * FROM employees


WHERE department_id = 90;

--4. Show the details of employees whose first name starts with 'A'.

SELECT *
FROM employees
WHERE first_name LIKE 'A%';

--5. Display the names and salaries of employees where commission is not null.

SELECT first_name, salary


FROM employees
WHERE commission_pct IS NOT NULL;

--6. List all unique job IDs in the HR schema.

SELECT DISTINCT job_id


FROM employees;

--7. Display employee names and salaries, sorted by salary descending.

SELECT first_name, salary


FROM employees
ORDER BY salary DESC;

--8. Show employee full names (first name + last name) using column alias as
"Employee Name".

SELECT first_name || ' ' || last_name AS "Employee Name"


FROM employees;

--9. Display employee names in uppercase.

SELECT UPPER(first_name) AS upper_name


FROM employees;

--10. Show employee names along with the length of their first name.
SELECT first_name, LENGTH(first_name) AS name_length
FROM employees;

--11. Round each employee s salary to the nearest hundred.

SELECT first_name, ROUND(salary, -2) AS rounded_salary


FROM employees;

--12. Show the current system date and time using a SELECT statement.

SELECT SYSDATE
FROM dual;

--13. Display employee names along with their department name.

SELECT e.first_name, d.department_name


FROM employees e
JOIN departments d ON e.department_id = d.department_id;

--14. List employees and their manager s name.

SELECT e.first_name AS employee, m.first_name AS manager


FROM employees e
JOIN employees m ON e.manager_id = m.employee_id;

--15. Show employee names, job titles, and department names.

SELECT e.first_name, e.job_id, d.department_name


FROM employees e
JOIN departments d ON e.department_id = d.department_id;

--16. Display the names of all employees along with the city they work in.

SELECT e.first_name, [Link]


FROM employees e
JOIN departments d ON e.department_id = d.department_id
JOIN locations l ON d.location_id = l.location_id;

--17. List employees along with their country name.

SELECT e.first_name, c.country_name


FROM employees e
JOIN departments d ON e.department_id = d.department_id
JOIN locations l ON d.location_id = l.location_id
JOIN countries c ON l.country_id = c.country_id;

--18. Find employees who earn more than the average salary.

SELECT *
FROM employees
WHERE salary > (SELECT AVG(salary)
FROM employees);

--19. List employees who have the same job ID as 'Steven King'.

SELECT *
FROM employees
WHERE job_id = (SELECT job_id
FROM employees
WHERE first_name = 'Steven' AND last_name = 'King');

--20. Show the name of the department where the maximum salary is paid.

SELECT department_id
FROM employees
WHERE salary = (SELECT MAX(salary) FROM employees);

--21. Find employees who work in the same department as Lex De Haan .

SELECT *
FROM employees
WHERE department_id = (SELECT department_id
FROM employees
WHERE first_name = 'Lex' AND last_name = 'De Haan');

--22. Display the total number of employees in each department.

SELECT department_id, COUNT(*) AS total_employees


FROM employees
GROUP BY department_id;

--23. Show the department ID with the highest average salary.

SELECT department_id
FROM employees
GROUP BY department_id
HAVING AVG(salary) = (
SELECT MAX(AVG(salary)) FROM employees GROUP BY department_id
);

--24. List departments having more than 5 employees.

SELECT department_id
FROM employees
GROUP BY department_id
HAVING COUNT(*) > 5;

--25. Find the total and average salary paid across the company. give query in
easiest way

SELECT SUM(salary) AS total_salary, AVG(salary) AS avg_salary


FROM employees;

You might also like