0% found this document useful (0 votes)
14 views9 pages

Mircoproject Queries

Uploaded by

murudkarp11
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)
14 views9 pages

Mircoproject Queries

Uploaded by

murudkarp11
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/ 9

Departments Table

INSERT INTO Departments (DepartmentName, ManagerID, Location,


PhoneNumber, Email, NumberOfEmployees, Budget, StartDate,
MissionStatement, DepartmentHeadcountLimit, ParentDepartmentID,
LastAnnualReviewDate, StrategicImportance, IsActive)
VALUES
('Human Resources', NULL, 'New York', '123-456-7890',
'[email protected]', 10, 500000.00, '2015-01-01', 'Ensure employee
satisfaction', 15, NULL, '2023-01-01', 'High', TRUE),
('Finance', NULL, 'San Francisco', '123-456-7891',
'[email protected]', 20, 1000000.00, '2016-01-01', 'Maintain
financial health', 20, NULL, '2023-01-01', 'High', TRUE),
('Marketing', NULL, 'Los Angeles', '123-456-7892',
'[email protected]', 15, 600000.00, '2017-01-01', 'Promote the
company', 25, NULL, '2023-01-01', 'Medium', TRUE),
('Sales', NULL, 'Chicago', '123-456-7893', '[email protected]', 30,
1500000.00, '2018-01-01', 'Increase revenue', 40, NULL, '2023-01-01',
'High', TRUE),
('IT', NULL, 'Boston', '123-456-7894', '[email protected]', 25, 800000.00,
'2015-05-01', 'Maintain technical infrastructure', 30, NULL, '2023-01-01',
'High', TRUE);
Employees Table
INSERT INTO Employees (FirstName, LastName, Gender, DateOfBirth,
HireDate, PhoneNumber, Email, Address, Position, DepartmentID,
ManagerID, MaritalStatus, Nationality, EmergencyContact)
VALUES
('John', 'Doe', 'M', '1980-05-15', '2015-06-01', '123-456-1111',
'[email protected]', '123 Main St, New York, NY', 'HR Manager', 1,
NULL, 'Married', 'American', 'Jane Doe'),
('Alice', 'Smith', 'F', '1985-03-20', '2016-01-10', '123-456-1112',
'[email protected]', '456 Elm St, San Francisco, CA', 'Finance
Manager', 2, NULL, 'Single', 'British', 'Mark Smith'),
('Bob', 'Johnson', 'M', '1990-11-30', '2017-02-15', '123-456-1113',
'[email protected]', '789 Oak St, Los Angeles, CA', 'Marketing
Manager', 3, NULL, 'Single', 'Canadian', 'Lisa Johnson'),
('Eve', 'Williams', 'F', '1982-04-10', '2018-05-20', '123-456-1114',
'[email protected]', '321 Pine St, Chicago, IL', 'Sales Manager',
4, NULL, 'Married', 'American', 'Chris Williams'),
('Charlie', 'Brown', 'M', '1975-09-25', '2015-07-15', '123-456-1115',
'[email protected]', '654 Maple St, Boston, MA', 'IT Manager',
5, NULL, 'Married', 'Australian', 'Sara Brown'),
('David', 'Lee', 'M', '1983-12-10', '2016-08-10', '123-456-1116',
'[email protected]', '789 Cedar St, New York, NY', 'HR Specialist', 1,
1, 'Single', 'American', 'Paul Lee'),
('Emma', 'Davis', 'F', '1989-07-25', '2016-09-01', '123-456-1117',
'[email protected]', '135 Birch St, San Francisco, CA', 'Finance
Specialist', 2, 2, 'Married', 'French', 'John Davis'),
('Frank', 'Miller', 'M', '1977-02-18', '2017-03-10', '123-456-1118',
'[email protected]', '246 Pine St, Los Angeles, CA', 'Marketing
Specialist', 3, 3, 'Single', 'Canadian', 'Jill Miller'),
('Grace', 'Wilson', 'F', '1991-11-05', '2018-04-15', '123-456-1119',
'[email protected]', '357 Palm St, Chicago, IL', 'Sales
Representative', 4, 4, 'Single', 'American', 'Matt Wilson'),
('Henry', 'Moore', 'M', '1984-05-12', '2016-07-01', '123-456-1120',
'[email protected]', '468 Oak St, Boston, MA', 'IT Specialist', 5,
5, 'Married', 'British', 'Anna Moore');

Salaries Table
INSERT INTO Salaries (EmployeeID, SalaryAmount, EffectiveDate, EndDate,
Bonus, OvertimeHours, OvertimePay, Deductions, TaxWithheld,
PensionContribution, InsuranceContribution, SalaryType, Currency,
IsActive)
VALUES
(1, 75000.00, '2015-06-01', '2016-06-01', 5000.00, 10, 500.00, 2000.00,
1500.00, 3000.00, 1200.00, 'Yearly', 'USD', TRUE),
(2, 90000.00, '2016-01-10', '2017-01-10', 7000.00, 8, 400.00, 2500.00,
1700.00, 4000.00, 1500.00, 'Yearly', 'USD', TRUE),
(3, 85000.00, '2017-02-15', '2018-02-15', 6000.00, 12, 600.00, 2200.00,
1600.00, 3500.00, 1400.00, 'Yearly', 'USD', TRUE),
(4, 95000.00, '2018-05-20', '2019-05-20', 8000.00, 15, 750.00, 2800.00,
1900.00, 5000.00, 1800.00, 'Yearly', 'USD', TRUE),
(5, 80000.00, '2015-07-15', '2016-07-15', 5500.00, 5, 250.00, 2100.00,
1700.00, 3200.00, 1300.00, 'Yearly', 'USD', TRUE),
(6, 60000.00, '2016-08-10', '2017-08-10', 3000.00, 20, 1000.00, 1800.00,
1200.00, 2500.00, 1000.00, 'Yearly', 'USD', TRUE),
(7, 72000.00, '2016-09-01', '2017-09-01', 4500.00, 10, 500.00, 2100.00,
1600.00, 3000.00, 1200.00, 'Yearly', 'USD', TRUE),
(8, 68000.00, '2017-03-10', '2018-03-10', 4200.00, 15, 750.00, 2000.00,
1500.00, 2700.00, 1100.00, 'Yearly', 'USD', TRUE),
(9, 62000.00, '2018-04-15', '2019-04-15', 3800.00, 18, 900.00, 2200.00,
1300.00, 2600.00, 1000.00, 'Yearly', 'USD', TRUE),
(10, 77000.00, '2016-07-01', '2017-07-01', 5500.00, 10, 500.00, 2300.00,
1700.00, 3100.00, 1200.00, 'Yearly', 'USD', TRUE);

QUERIES:
1. Select all employees
SELECT * FROM Employees;
2. Select employees' first and last names only
SELECT FirstName, LastName FROM Employees;
3. Select all distinct positions in the company
SELECT DISTINCT Position FROM Employees;
4. Count the total number of employees.
SELECT COUNT(*) AS TotalEmployees FROM Employees;
5. Count the number of employees in each department
SELECT DepartmentID, COUNT(*) AS NumberOfEmployees FROM Employees GROUP
BY DepartmentID;
6. List employees who are managers (ManagerID is NULL)
SELECT * FROM Employees WHERE ManagerID IS NULL;
7. List all employees hired after 2016
SELECT * FROM Employees WHERE HireDate > '2016-01-01';
8. Get employees whose nationality is American
SELECT * FROM Employees WHERE Nationality = 'American';
9. Get employees with a salary greater than $70,000
SELECT e.FirstName, e.LastName, s.SalaryAmount
FROM Employees e
JOIN Salaries s ON e.EmployeeID = s.EmployeeID
WHERE s.SalaryAmount > 70000;
10. Find the average salary of all employees
SELECT AVG(SalaryAmount) AS AverageSalary FROM Salaries;
11. Get the total bonuses given to employees
SELECT SUM(Bonus) AS TotalBonuses FROM Salaries;

12. Find the highest salary in the company


SELECT MAX(SalaryAmount) AS HighestSalary FROM Salaries;
13. Find the employee with the lowest salary
SELECT e.FirstName, e.LastName, s.SalaryAmount
FROM Employees e
JOIN Salaries s ON e.EmployeeID = s.EmployeeID
ORDER BY s.SalaryAmount ASC
LIMIT 1;
14. Get all employees with their department details
SELECT e.FirstName, e.LastName, d.DepartmentName
FROM Employees e
JOIN Departments d ON e.DepartmentID = d.DepartmentID;
15. Get the total number of employees in each department, along with
department names
SELECT d.DepartmentName, COUNT(e.EmployeeID) AS NumberOfEmployees
FROM Departments d
LEFT JOIN Employees e ON d.DepartmentID = e.DepartmentID
GROUP BY d.DepartmentName;
16. List employees along with their current salary
SELECT e.FirstName, e.LastName, s.SalaryAmount
FROM Employees e
JOIN Salaries s ON e.EmployeeID = s.EmployeeID
WHERE s.IsActive = TRUE;
17. Find all employees who work in the IT department
SELECT e.FirstName, e.LastName
FROM Employees e
JOIN Departments d ON e.DepartmentID = d.DepartmentID
WHERE d.DepartmentName = 'IT';
18. Find employees who have a bonus greater than $5,000
SELECT e.FirstName, e.LastName, s.Bonus
FROM Employees e
JOIN Salaries s ON e.EmployeeID = s.EmployeeID
WHERE s.Bonus > 5000;
19. List all departments along with their budget
SELECT DepartmentName, Budget FROM Departments;
20. Find employees who have worked overtime
SELECT e.FirstName, e.LastName, s.OvertimeHours
FROM Employees e
JOIN Salaries s ON e.EmployeeID = s.EmployeeID
WHERE s.OvertimeHours > 0;
21. Get the total overtime pay of all employees
SELECT SUM(OvertimePay) AS TotalOvertimePay FROM Salaries;
22. List employees and their total deductions
SELECT e.FirstName, e.LastName, s.Deductions
FROM Employees e
JOIN Salaries s ON e.EmployeeID = s.EmployeeID;
23. Find the employee with the highest bonus
SELECT e.FirstName, e.LastName, s.Bonus
FROM Employees e
JOIN Salaries s ON e.EmployeeID = s.EmployeeID
ORDER BY s.Bonus DESC
LIMIT 1;

24. Get all employees in the 'Marketing' department


SELECT e.FirstName, e.LastName
FROM Employees e
JOIN Departments d ON e.DepartmentID = d.DepartmentID
WHERE d.DepartmentName = 'Marketing';
25. Count the number of employees hired in each year
SELECT YEAR(HireDate) AS HireYear, COUNT(*) AS NumberOfHires
FROM Employees
GROUP BY HireYear;
26. Find employees who have not received a bonus
SELECT e.FirstName, e.LastName
FROM Employees e
JOIN Salaries s ON e.EmployeeID = s.EmployeeID
WHERE s.Bonus = 0;
27. List employees with their salary, bonus, and deductions
SELECT e.FirstName, e.LastName, s.SalaryAmount, s.Bonus, s.Deductions
FROM Employees e
JOIN Salaries s ON e.EmployeeID = s.EmployeeID;
28. Get employees whose salary is between $60,000 and $80,000
SELECT e.FirstName, e.LastName, s.SalaryAmount
FROM Employees e
JOIN Salaries s ON e.EmployeeID = s.EmployeeID
WHERE s.SalaryAmount BETWEEN 60000 AND 80000;

29. Find the number of employees in each salary bracket (e.g., $50K–$70K,
$70K–$90K)
SELECT
CASE
WHEN SalaryAmount BETWEEN 50000 AND 70000 THEN '50K-70K'
WHEN SalaryAmount BETWEEN 70001 AND 90000 THEN '70K-90K'
ELSE '90K+'
END AS SalaryRange,
COUNT(*) AS NumberOfEmployees
FROM Salaries
GROUP BY SalaryRange;
30. Find employees who joined before 2017 and earn more than $80,000
SELECT e.FirstName, e.LastName, s.SalaryAmount
FROM Employees e
JOIN Salaries s ON e.EmployeeID = s.EmployeeID
WHERE e.HireDate < '2017-01-01' AND s.SalaryAmount > 80000;
31. List employees whose salary has increased over time
SELECT e.FirstName, e.LastName, s.SalaryAmount, s.EffectiveDate
FROM Employees e
JOIN Salaries s ON e.EmployeeID = s.EmployeeID
WHERE s.EndDate IS NOT NULL
ORDER BY e.EmployeeID, s.EffectiveDate;
32. Get the total tax withheld from all employees
SELECT SUM(TaxWithheld) AS TotalTaxWithheld FROM Salaries

33. Find the department with the highest number of employees


SELECT d.DepartmentName, COUNT(e.EmployeeID) AS NumberOfEmployees
FROM Departments d
JOIN Employees e ON d.DepartmentID = e.DepartmentID
GROUP BY d.DepartmentName
ORDER BY NumberOfEmployees DESC1
LIMIT 1;
34. List all employees along with their department's budget
SELECT e.FirstName, e.LastName, d.Budget
FROM Employees e
JOIN Departments d ON e.DepartmentID = d.DepartmentID;
35. Get employees whose salary is above the average salary
SELECT e.FirstName, e.LastName, s.SalaryAmount
FROM Employees e
JOIN Salaries s ON e.EmployeeID = s.EmployeeID
WHERE s.SalaryAmount > (SELECT AVG(SalaryAmount) FROM Salaries);

You might also like