0% found this document useful (0 votes)
12 views

SQL Questions

Uploaded by

dandgenik
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views

SQL Questions

Uploaded by

dandgenik
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

CREATE TABLE Employees (

EmployeeID INT PRIMARY KEY,


FirstName VARCHAR(50),
LastName VARCHAR(50),
Department VARCHAR(50),
Salary DECIMAL(10, 2),
HireDate DATE
);

1. Retrieve all information about all employees.


2. Retrieve only the first and last names of all employees.
3. Retrieve the employees who work in the Engineering department.

4. Retrieve the employees hired after January 1st, 2020.


5. Retrieve the employees whose salary is greater than $60,000.
6. Retrieve the total number of employees.
7. Retrieve the average salary of all employees.
8. Retrieve the maximum salary among all employees.

9. Retrieve the minimum salary among all employees.


10. Retrieve the employees ordered by their hire date in ascending order.
11. Retrieve the employees ordered by their salary in descending order.

12. Retrieve the number of employees in each department.


13. Retrieve the employee with the highest salary.
14. Retrieve the employee with the lowest salary.

15. Retrieve the employees whose first name starts with 'J'.
16. Retrieve the employees whose last name ends with 'son'.

17. Retrieve the employees hired in the year 2019.


18. Retrieve the employees whose salary is between $50,000 and $70,000.

19. Retrieve the employees who do not work in the Engineering department.
20. Retrieve the employees hired in the month of January.
-----------------------------------X----------------------------------
X------------------------

1. Retrieve the total salary expenditure for each department.


2. Retrieve the average salary for each department.
3. Retrieve the department with the highest average salary.
4. Retrieve the departments where the total salary expenditure is greater than
$200,000.
5. Retrieve the number of employees in each department, ordered by the number of
employees in descending order.
6. Retrieve the average salary of employees hired in each year.
7. Retrieve the department with the highest number of employees.
8. Retrieve the department with the lowest average salary.
9. Retrieve the total number of distinct departments.
10. Retrieve the employees with the highest salary in each department.
11. Retrieve the departments with more than three employees.
12. Retrieve the employees with the same first name.
13. Retrieve the first names of all employees without duplication.
14. Retrieve the employees who have the same salary.
15. Retrieve the number of employees who have been hired in the same year.
16. Retrieve the departments where the average salary is higher than the overall
average salary of all employees.
17. Retrieve the employees who earn more than the average salary of their
department.
18. Retrieve the employees who earn less than the average salary of their
department.
19. Retrieve the departments where the maximum salary is higher than $70,000.
20. Retrieve the departments where at least one employee's salary is less than
$60,000.

1. Retrieve all employee records sorted by their hire date in descending order.
2. List the first names of employees in ascending order, limiting the results to
the top 10.
3. How many employees work in each department?
4. What is the highest salary in the Engineering department?
5. Find the total number of employees who were hired before 2019.
6. Which department has the lowest average salary?
7. List all distinct job departments from the Employees table.
8. Count the total number of unique first names in the Employees table.
9. Identify the employee with the third highest salary.
10. How many employees have a first name that contains the letter "a"?
11. List the names of employees who do not have the letter "e" in their first
names.
12. What is the average salary of all employees, excluding the highest earner?
13. Retrieve the details of employees whose salary is above the company average.
14. How many employees were hired on the last day of any month?
15. Which year saw the highest number of employees being hired?
16. List the employees whose names start with "J" and end with "n".
17. Retrieve the total salary paid to employees in the Marketing department.
18. Find employees whose last names are at least 5 characters long.
19. What is the difference in salary between the highest and lowest paid employees?
20. How many employees have a salary within the top 10% of the company?

SELECT e.employeeid, e.firstname, e.salary, e.department


FROM employees e
INNER JOIN (
SELECT department, AVG(salary) AS avg_salary
FROM employees
GROUP BY department
) AS dept_avg ON e.department = dept_avg.department
WHERE e.salary > dept_avg.avg_salary;

SELECT department
FROM employees
WHERE department IN (
SELECT DISTINCT department
FROM employees
WHERE salary < 60000
);

You might also like