INDEX
Sl Assignment Name
01 Bank Database
02 Employee Database
03 Employee Database (Update/Delete queries)
Assignment 1: Bank Database
Tables: Branch, Customer, Account, Loan, Depositor, Borrower
Queries:
I. Retrieve distinct customers who have either an account or a loan.
SELECT DISTINCT C.CustomerID, C.CustomerName
FROM Customer C
WHERE C.CustomerID IN (SELECT CustomerID FROM Depositor)
OR C.CustomerID IN (SELECT CustomerID FROM Borrower);
II. Retrieve the branch with the maximum number of accounts.
SELECT BranchName
FROM Account
GROUP BY BranchName
ORDER BY COUNT(AccountNumber) DESC
LIMIT 1;
III. Find the maximum loan amount issued in each branch.
SELECT BranchName, MAX(Amount) AS MaxLoan
FROM Loan
GROUP BY BranchName;
IV. Find customers whose names start with 'A'.
SELECT *
FROM Customer
WHERE CustomerName LIKE 'A%';
Assignment 2: Employee Database
Tables: employee, works, company, manages
Queries:
I. Find the company that has the most employees.
SELECT CompanyName
FROM works
GROUP BY CompanyName
ORDER BY COUNT(EmployeeID) DESC
LIMIT 1;
II. Find employees who do not have a manager.
SELECT E.EmployeeID, E.EmployeeName
FROM employee E
WHERE E.EmployeeID NOT IN (SELECT EmployeeID FROM manages);
III. Find the second highest salary among employees.
SELECT DISTINCT Salary
FROM works
ORDER BY Salary DESC
LIMIT 1 OFFSET 1;
IV. Find all employees who live in Dhaka city, but their company is not in Dhaka.
SELECT E.EmployeeID, E.EmployeeName
FROM employee E
JOIN works W ON E.EmployeeID = W.EmployeeID
JOIN company C ON W.CompanyName = C.CompanyName
WHERE E.City = 'Dhaka' AND C.City <> 'Dhaka';
Assignment 3: Employee Database (Update/Delete queries)
Tables: employee, works, company, manages
Queries:
I. Find companies with more than 5 employees.
SELECT CompanyName
FROM works
GROUP BY CompanyName
HAVING COUNT(EmployeeID) > 5;
II. Give all employees of First Bank Corporation a 20% salary raise.
UPDATE works
SET Salary = Salary * 1.20
WHERE CompanyName = 'First Bank Corporation';
III. Delete all records where an employee has no manager.
DELETE FROM manages
WHERE ManagerID IS NULL;
IV. Assign a new manager to employees who currently have no manager. (Example:
ManagerID = 101)
UPDATE manages
SET ManagerID = 101
WHERE ManagerID IS NULL;