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

Create Employee Table

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views

Create Employee Table

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

Create employee table:

CREATE TABLE employees (


employee_id INT PRIMARY KEY,
name VARCHAR(100),
department VARCHAR(50),
salary DECIMAL(10, 2),
hire_date DATE
);

INSERT INTO employees (employee_id, name, department, salary, hire_date) VALUES


(1, 'Suman Adhikari', 'IT', 90000.00, '2021-05-10'),
(2, 'Kiran Shrestha', 'HR', 75000.00, '2020-02-15'),
(3, 'Sarita Dhungana', 'Finance', 85000.00, '2019-11-20'),
(4, 'Ramesh Karki', 'IT', 95000.00, '2018-07-25'),
(5, 'Rita Thapa', 'Marketing', 65000.00, '2021-01-12'),
(6, 'Mina Lama', 'HR', 70000.00, '2020-03-22'),
(7, 'Rajesh Hamal', 'Finance', 80000.00, '2019-05-14'),
(8, 'Sunita Ghimire', 'IT', 88000.00, '2018-09-10'),
(9, 'Krishna Basnet', 'Marketing', 72000.00, '2021-06-18'),
(10, 'Gopal Khadka', 'Finance', 77000.00, '2020-12-02'),
(11, 'Bimala Rai', 'IT', 92000.00, '2018-03-25'),
(12, 'Kushal Ranjit', 'HR', 69000.00, '2019-08-30'),
(13, 'Anita Bhandari', 'Marketing', 68000.00, '2021-10-05'),
(14, 'Suresh Pokhrel', 'Finance', 82000.00, '2020-07-17'),
(15, 'Puja Maharjan', 'IT', 87000.00, '2019-04-11'),
(16, 'Dipesh Shahi', 'HR', 74000.00, '2018-11-20'),
(17, 'Anil Joshi', 'Marketing', 76000.00, '2021-12-25'),
(18, 'Laxmi Gurung', 'Finance', 83000.00, '2020-09-10'),
(19, 'Hari Dahal', 'IT', 91000.00, '2019-03-14'),
(20, 'Nirjala Neupane', 'HR', 72000.00, '2018-10-05');
Questions:
1. Calculate the total number of employees in each department and order by total employees
in descending order.

2. Find the average salary of employees in each department and order by average salary in
ascending order.
3. Determine the maximum salary in each department and order by department name.

4. List the departments where the total salary exceeds 100,000 and order by total salary in
descending order.

5. Get the minimum salary of employees hired after January 1, 2020, in each department
and order by department name.

6. Show the number of employees in each department where the department has more than
5 employees, ordered by employee count.
7. Find the sum of salaries for each department, but only include departments with an
average salary greater than 50,000, ordered by total salary.

8. Calculate the average salary of employees grouped by the month and year of their hire
date, ordered by year and month.
SELECT EXTRACT(YEAR FROM hire_date) AS year, EXTRACT(MONTH
FROM hire_date) AS month, AVG(salary) AS average_salary FROM employees
GROUP BY EXTRACT(YEAR FROM hire_date), EXTRACT(MONTH FROM
hire_date) ORDER BY year, month;

9. Identify departments where the highest salary is below 80,000 and order by highest
salary.

10. List the average salary and total number of employees for each department, but exclude
departments with less than 3 employees, ordered by average salary.

11. Find the total salary paid to employees hired in 2020, grouped by department, and order
by total salary in descending order.
SELECT department, SUM(salary) AS total_salary FROM employees WHERE
EXTRACT(YEAR FROM hire_date) = 2020 GROUP BY department ORDER BY
total_salary DESC;

12. Calculate the maximum salary of employees in each department, but only for
departments with more than 5 employees, ordered by department name.

13. Show the average salary for each department, but only include salaries greater than
60,000 in the calculation, ordered by average salary.
14. List the total number of employees and the average salary in each department, but only
for departments where the total salary exceeds 150,000, ordered by total employees.
15. Find the minimum salary of employees in each department who were hired after July 1,
2019, ordered by minimum salary.
16. Identify departments where the number of employees hired after January 1, 2018, is more
than 3, ordered by number of employees.
17. Show the department-wise total salary, but only include employees with salaries between
70,000 and 90,000, ordered by total salary.
18. Find the number of employees in each department where the minimum salary is greater
than 65,000, ordered by number of employees.
19. List the total salary and average salary for each department where the highest salary is
less than 100,000, ordered by average salary.
20. List the departments where the total number of employees is between 5 and 10, ordered
by department name.
21. Identify departments where the sum of salaries is within the top 3 highest sums, ordered
by total salary.
SELECT department, SUM(salary) AS total_salary
FROM employees
GROUP BY department
ORDER BY total_salary DESC
LIMIT 3;
22. Show the total salary and average salary for each department, ordered by the number of
employees in descending order.
23. List departments where the maximum salary is more than double the minimum salary,
ordered by department name.
24. Identify departments with more than 3 employees earning over 80,000, ordered by
department name.
25. Show the department with the highest number of employees earning less than 70,000,
ordered by department name.

You might also like