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

Company Management System Assignment

Uploaded by

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

Company Management System Assignment

Uploaded by

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

Company Management System

CREATE TABLE Departments (


dept_id INT PRIMARY KEY,
dept_name VARCHAR(50)
);

INSERT INTO Departments VALUES


(1, 'HR'),
(2, 'IT'),
(3, 'Finance'),
(4, 'Marketing');

CREATE TABLE Employees (


emp_id INT PRIMARY KEY,
emp_name VARCHAR(100),
dept_id INT,
hire_date DATE,
email VARCHAR(100),
salary DECIMAL(10,2),
CONSTRAINT fk_dept FOREIGN KEY (dept_id) REFERENCES Departments(dept_id)
);

INSERT INTO Employees VALUES


(1, 'Alice Johnson', 2, '2018-06-15', '[email protected]', 75000),
(2, 'Bob Smith', 1, '2019-09-23', '[email protected]', 50000),
(3, 'Charlie Brown', 3, '2017-03-10', '[email protected]', 85000),
(4, 'David Wilson', 2, '2020-11-05', '[email protected]', 65000),
(5, 'Eva Adams', 4, '2016-07-30', '[email protected]', 78000);

CREATE TABLE Salaries (


emp_id INT,
salary DECIMAL(10,2),
bonus DECIMAL(10,2),
PRIMARY KEY (emp_id),
CONSTRAINT fk_salary FOREIGN KEY (emp_id) REFERENCES Employees(emp_id)
);

INSERT INTO Salaries VALUES


(1, 75000, 5000),
(2, 50000, 3000),
(3, 85000, 7000),
(4, 65000, 4000),
(5, 78000, 6000);

CREATE TABLE Projects (


project_id INT PRIMARY KEY,
project_name VARCHAR(100),
budget DECIMAL(10,2)
);

INSERT INTO Projects VALUES


(101, 'AI Research', 200000),
(102, 'E-commerce Website', 150000),
(103, 'Financial Analysis', 180000),
(104, 'Marketing Campaign', 120000);

CREATE TABLE Employee_Projects (


emp_id INT,
project_id INT,
hours_worked INT,
PRIMARY KEY (emp_id, project_id),
CONSTRAINT fk_emp FOREIGN KEY (emp_id) REFERENCES Employees(emp_id),
CONSTRAINT fk_proj FOREIGN KEY (project_id) REFERENCES Projects(project_id)
);

INSERT INTO Employee_Projects VALUES


(1, 101, 120),
(1, 102, 80),
(2, 104, 100),
(3, 103, 150),
(4, 102, 90),
(5, 104, 130);

SQL Questions
1. Retrieve all employees along with their department names.
2. Find employees who have worked on projects and list their names, project names, and hours
worked.
3. Get the total salary (salary + bonus) of each employee by joining the Employees and
Salaries tables.
4. List all employees and their projects, including those who are not assigned to any project.
5. Retrieve all projects along with the employees assigned to them, including projects with no
employees assigned.
6. Find employees who have not been assigned any project.
7. Retrieve employees whose name starts with ‘A’.
8. Extract the domain name from each employee's email.
9. Find the total number of employees.
10. Calculate the average salary of employees.
11. Find the highest salary among employees.
12. Find the department with the highest number of employees.
13. Get the total hours worked by each employee.
14. Find employees earning more than the average salary.
15. Find the employee who has worked the most hours on a project.
16. Retrieve projects that have at least two employees working on them.
17. Get the department with the highest total salary.

Advanced SQL Questions


1. Find employees who are working on all projects (i.e., employees assigned to every project).
2. Retrieve employees who have never worked on a project in the last 6 months.
3. Find employees who are getting a salary higher than the average salary of their department.
4. Find employees who work in multiple departments.
5. Get the name of employees who have the second-highest salary.
6. Rank employees by salary within their department.
7. Find employees who have the highest salary in their department.
8. Calculate the cumulative salary paid to employees in order of hire date.
9. Get the previous employee’s salary for each employee (ordered by hire date).
10. Find the percentage of total company salary that each employee earns.
11. Find all employees under a given manager (assuming a self-referential table for hierarchy).
12. Find the total salary of an employee and all their subordinates.
13. Extract first name and last name from emp_name.
15. Find employees whose email contains their name.
16. Find employees who were hired on a Monday.
17. Find employees who earn above the company’s median salary.
18. Find employees who have worked the most hours but are not the highest-paid.
19. Find employees who have a salary close (within 10%) to the highest-paid employee.
20. Find departments where the highest-paid employee earns at least double the lowest-paid
employee in the same department.

You might also like