Added running queries, testing pending from 4-16.
This commit is contained in:
parent
cea00df703
commit
588dac9604
@ -1,6 +1,6 @@
|
|||||||
# Queries for Assignment-A2
|
# Database Queries for Assignment-A2
|
||||||
|
|
||||||
This file contains all the queries required to build the [database](https://git.kska.io/DatabaseManagementSystems/src/branch/main/Practical/Assignment-A2/Database_A2.sql)
|
This file contains all the queries required to build the [database](https://git.kska.io/sppu-te-comp-content/DatabaseManagementSystems/src/branch/main/Practical/Assignment-A2/Database_A2.sql)
|
||||||
|
|
||||||
## Creating database
|
## Creating database
|
||||||
|
|
||||||
@ -63,8 +63,8 @@ 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", 900),
|
(158, "Bishops", 9000),
|
||||||
(159, "Amanora", 2500);
|
(159, "Amanora", 25000);
|
||||||
|
|
||||||
INSERT INTO Borrower VALUES
|
INSERT INTO Borrower VALUES
|
||||||
("Kalas", 156),
|
("Kalas", 156),
|
||||||
@ -88,4 +88,141 @@ INSERT INTO Depositor VALUES
|
|||||||
|
|
||||||
## Running queries
|
## Running queries
|
||||||
|
|
||||||
==PENDING==
|
1. Find the names of all branches in loan relation.
|
||||||
|
|
||||||
|
```sql
|
||||||
|
SELECT branchName FROM Loan;
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
2. Find all loan numbers for loans made at Akurdi Branch with loan amount > 12000.
|
||||||
|
|
||||||
|
```sql
|
||||||
|
SELECT loanNum FROM Loan WHERE amount>12000;
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
3. Find all customers who have a loan from bank. Find their names,loan_no and loan amount.
|
||||||
|
|
||||||
|
```sql
|
||||||
|
SELECT * from Borrower;
|
||||||
|
SELECT Borrower.loanNum FROM Borrower INNER JOIN Loan ON Borrower.loanNum = Loan.loanNum;
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
==TESTING PENDING==
|
||||||
|
|
||||||
|
4. List all customers in alphabetical order who have loan from Akurdi branch.
|
||||||
|
|
||||||
|
```sql
|
||||||
|
SELECT 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.
|
||||||
|
|
||||||
|
```sql
|
||||||
|
SELECT DISTINCT customerName
|
||||||
|
FROM (SELECT customerName FROM Account UNION SELECT customerName FROM Borrower) AS Customers;
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
6. Find all customers who have both account and loan at bank.
|
||||||
|
|
||||||
|
```sql
|
||||||
|
SELECT customerName
|
||||||
|
FROM Account
|
||||||
|
WHERE customerName IN (SELECT customerName FROM Borrower);
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
7. Find all customers who have account but no loan at the bank.
|
||||||
|
|
||||||
|
```sql
|
||||||
|
SELECT customerName
|
||||||
|
FROM Account
|
||||||
|
WHERE customerName NOT IN (SELECT customerName FROM Borrower);
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
8. Find the average account balance at each branch
|
||||||
|
|
||||||
|
```sql
|
||||||
|
SELECT branchName, AVG(balance) AS avg_balance
|
||||||
|
FROM Account
|
||||||
|
GROUP BY branchName;
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
9. Find no. of depositors at each branch.
|
||||||
|
|
||||||
|
```sql
|
||||||
|
SELECT branchName, COUNT(DISTINCT customerName) AS num_depositors
|
||||||
|
FROM Account
|
||||||
|
GROUP BY branchName;
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
10. Find name of Customer and city where customer name starts with Letter P.
|
||||||
|
|
||||||
|
```sql
|
||||||
|
SELECT customerName, city
|
||||||
|
FROM Customer
|
||||||
|
WHERE customerName LIKE 'P%';
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
11. Display distinct cities of branch.
|
||||||
|
|
||||||
|
```sql
|
||||||
|
SELECT DISTINCT city
|
||||||
|
FROM Branch;
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
12. Find the branches where average account balance > 12000
|
||||||
|
|
||||||
|
```sql
|
||||||
|
SELECT branchName
|
||||||
|
FROM Account
|
||||||
|
GROUP BY branchName
|
||||||
|
HAVING AVG(balance) > 12000;
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
13. Find number of tuples in customer relation.
|
||||||
|
|
||||||
|
```sql
|
||||||
|
SELECT COUNT(*) AS num_tuples
|
||||||
|
FROM Customer;
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
14. Calculate total loan amount given by bank.
|
||||||
|
|
||||||
|
```sql
|
||||||
|
SELECT SUM(amount) AS total_loan_amount
|
||||||
|
FROM Loan;
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
15. Delete all loans with loan amount between 1300 and 1500.
|
||||||
|
|
||||||
|
```sql
|
||||||
|
DELETE FROM Loan
|
||||||
|
WHERE amount BETWEEN 1300 AND 1500;
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
16. Delete all tuples at every branch located in Nigdi.
|
||||||
|
|
||||||
|
```sql
|
||||||
|
DELETE FROM Account
|
||||||
|
WHERE branchName IN (SELECT branchName FROM Branch WHERE city = 'Nigdi');
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
Loading…
Reference in New Issue
Block a user