Tested all running queries and fixed the ones that weren't working.
This commit is contained in:
parent
2c647c95b8
commit
0c4e665809
@ -63,7 +63,7 @@ INSERT INTO Loan (loanNum, branchName, amount) VALUES
|
|||||||
(155, "Dhole Patil", 500),
|
(155, "Dhole Patil", 500),
|
||||||
(156, "Nagarwala", 250),
|
(156, "Nagarwala", 250),
|
||||||
(157, "Peachtree", 600),
|
(157, "Peachtree", 600),
|
||||||
(158, "Bishops", 9000),
|
(158, "Bishops", 1400),
|
||||||
(159, "Amanora", 25000);
|
(159, "Amanora", 25000);
|
||||||
|
|
||||||
INSERT INTO Borrower VALUES
|
INSERT INTO Borrower VALUES
|
||||||
@ -110,118 +110,99 @@ SELECT Borrower.loanNum FROM Borrower INNER JOIN Loan ON Borrower.loanNum = Loan
|
|||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
==TESTING PENDING==
|
|
||||||
|
|
||||||
4. List all customers in alphabetical order who have loan from Akurdi branch.
|
4. List all customers in alphabetical order who have loan from Akurdi branch.
|
||||||
|
|
||||||
```sql
|
```sql
|
||||||
SELECT customerName
|
SELECT customerName FROM Borrower INNER JOIN Loan ON Borrower.loanNum = Loan.loanNum WHERE branchName = "Akurdi" ORDER BY customerName;
|
||||||
FROM Borrower
|
|
||||||
WHERE loanNum IN (SELECT loanNum FROM Loan WHERE branchName = 'Akurdi')
|
|
||||||
ORDER BY customerName;
|
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
5. Find all customers who have an account or loan or both at bank.
|
5. Find all customers who have an account or loan or both at bank.
|
||||||
|
|
||||||
```sql
|
```sql
|
||||||
SELECT DISTINCT customerName
|
SELECT customerName FROM Depositor UNION SELECT customerName FROM Borrower;
|
||||||
FROM (SELECT customerName FROM Account UNION SELECT customerName FROM Borrower) AS Customers;
|
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
6. Find all customers who have both account and loan at bank.
|
6. Find all customers who have both account and loan at bank.
|
||||||
|
|
||||||
```sql
|
```sql
|
||||||
SELECT customerName
|
SELECT customerName FROM Depositor INTERSECT SELECT customerName FROM Borrower;
|
||||||
FROM Account
|
|
||||||
WHERE customerName IN (SELECT customerName FROM Borrower);
|
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
7. Find all customers who have account but no loan at the bank.
|
7. Find all customers who have account but no loan at the bank.
|
||||||
|
|
||||||
```sql
|
```sql
|
||||||
SELECT customerName
|
SELECT customerName FROM Depositor WHERE customerName NOT IN (SELECT customerName FROM Borrower);
|
||||||
FROM Account
|
|
||||||
WHERE customerName NOT IN (SELECT customerName FROM Borrower);
|
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
8. Find the average account balance at each branch
|
8. Find the average account balance at each branch
|
||||||
|
|
||||||
```sql
|
```sql
|
||||||
SELECT branchName, AVG(balance) AS avg_balance
|
SELECT AVG(amount) FROM Loan;
|
||||||
FROM Account
|
|
||||||
GROUP BY branchName;
|
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
9. Find no. of depositors at each branch.
|
9. Find no. of depositors at each branch.
|
||||||
|
|
||||||
```sql
|
```sql
|
||||||
SELECT branchName, COUNT(DISTINCT customerName) AS num_depositors
|
SELECT branchName, COUNT(*) AS noOfDepositors FROM Account JOIN Depositor ON Account.accountNum = Depositor.accountNum GROUP BY branchName;
|
||||||
FROM Account
|
|
||||||
GROUP BY branchName;
|
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
10. Find name of Customer and city where customer name starts with Letter P.
|
10. Find name of Customer and city where customer name starts with Letter K.
|
||||||
|
|
||||||
```sql
|
```sql
|
||||||
SELECT customerName, city
|
SELECT customerName, customerCity from Customer where customerName like "K%";
|
||||||
FROM Customer
|
|
||||||
WHERE customerName LIKE 'P%';
|
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
11. Display distinct cities of branch.
|
11. Display distinct cities of branch.
|
||||||
|
|
||||||
```sql
|
```sql
|
||||||
SELECT DISTINCT city
|
SELECT DISTINCT branchName, branchCity FROM Branch;
|
||||||
FROM Branch;
|
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
12. Find the branches where average account balance > 12000
|
12. Find the branches where average account balance > 1200
|
||||||
|
|
||||||
```sql
|
```sql
|
||||||
SELECT branchName
|
SELECT branchName FROM Account GROUP BY branchName HAVING AVG(balance) > 1200;
|
||||||
FROM Account
|
|
||||||
GROUP BY branchName
|
|
||||||
HAVING AVG(balance) > 12000;
|
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
13. Find number of tuples in customer relation.
|
13. Find number of tuples in customer relation.
|
||||||
|
|
||||||
```sql
|
```sql
|
||||||
SELECT COUNT(*) AS num_tuples
|
SELECT COUNT(*) FROM Customer;
|
||||||
FROM Customer;
|
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
14. Calculate total loan amount given by bank.
|
14. Calculate total loan amount given by bank.
|
||||||
|
|
||||||
```sql
|
```sql
|
||||||
SELECT SUM(amount) AS total_loan_amount
|
SELECT SUM(amount) AS amount FROM Loan;
|
||||||
FROM Loan;
|
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
15. Delete all loans with loan amount between 1300 and 1500.
|
15. Delete all loans with loan amount between 1300 and 1500.
|
||||||
|
|
||||||
```sql
|
```sql
|
||||||
DELETE FROM Loan
|
DELETE FROM Borrower WHERE loanNum IN (SELECT loanNum FROM Loan WHERE amount > 1300 AND amount < 1500);
|
||||||
WHERE amount BETWEEN 1300 AND 1500;
|
DELETE FROM Loan WHERE amount > 1300 AND amount < 1500;
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
16. Delete all tuples at every branch located in Nigdi.
|
16. Delete all tuples at every branch located in Nigdi.
|
||||||
|
|
||||||
```sql
|
```sql
|
||||||
DELETE FROM Account
|
DELETE FROM Borrower WHERE loanNum IN (SELECT loanNum FROM Loan WHERE branchName IN (SELECT branchName FROM Branch WHERE branchCity = "Nigdi"));
|
||||||
WHERE branchName IN (SELECT branchName FROM Branch WHERE city = 'Nigdi');
|
DELETE FROM Loan WHERE branchName = (SELECT branchName FROM Branch WHERE branchCity = "Nigdi");
|
||||||
|
DELETE FROM Depositor WHERE accountNum IN (SELECT accountNum FROM Account WHERE branchName IN (SELECT branchName FROM Branch WHERE branchCity = "Nigdi"));
|
||||||
|
DELETE FROM Account WHERE branchName = (SELECT branchName FROM Branch WHERE branchCity = "Nigdi");
|
||||||
|
DELETE FROM Branch WHERE branchName = “Nigdi”;
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user