Practical No 09
Practical No 09
03
Name : Renuka Jadhav Roll No. : 49
Div : C
Aim : Write at least10 SQL queries for suitable database application using SQL DML
statements , Join , Sub-Query and View.
+-------------+-------------+--------+
| akurdi | pune | 12000 |
| latur | latur | 45888 |
| loni | pune | 67000 |
| wagholi | pune | 5699 |
+-------------+-------------+--------+
4 rows in set (0.01 sec)
mysql> insert into customer
values("renuka","balajinagar","dhoki"),("ishwari","shivajinagar","satara"),("jayjit","lokmanyatilk
","pune"),("srushti","mg","latur");
Query OK, 4 rows affected (0.02 sec)
Records: 4 Duplicates: 0 Warnings: 0
| customer_name | account_number |
+---------------+----------------+
| ishwari | 101 |
| jayjit | 102 |
+---------------+----------------+
2 rows in set (0.00 sec)
+---------------+-------------+
| customer_name | loan_number |
+---------------+-------------+
| renuka | 201 |
| srushti | 202 |
+---------------+-------------+
2 rows in set (0.00 sec)
+---------------+-------------+
| renuka | 201 |
| srushti | 202 |
+---------------+-------------+
2 rows in set (0.01 sec)
| latur |
+-------------+
2 rows in set (0.01 sec)
3) find all loan number for loan where at Akurdi branch with loan amount < 12000
mysql> select loan_number,amount from Loan where branch_name='Akurdi' and
amount>12000;
+-------------+--------+
| loan_number | amount |
+-------------+--------+
| 201 | 23000 |
+-------------+--------+
4) Find all the customer who have a loan from bank & find there names, loan number ,
loan amount
mysql> select borrower.customer_name, loan.loan_number,loan.amount from borrower inner
join loan on borrower.loan_number = loan.loan_number;
+---------------+-------------+--------+
| customer_name | loan_number | amount |
+---------------+-------------+--------+
| renuka | 201 | 23000 |
| srushti | 202 | 56000 |
+---------------+-------------+--------+
2 rows in set (0.00 sec)
+-------------+-------------+--------+---------------+-------------+
| loan_number | branch_name | amount | customer_name | loan_number |
+-------------+-------------+--------+---------------+-------------+
| 201 | akurdi | 23000 | renuka | 201 |
| 202 | latur | 56000 | srushti | 202 |
+-------------+-------------+--------+---------------+-------------+
2 rows in set (0.00 sec)
6) List all customer in alphabetical order who have loan from Akurdi branch
mysql> select customer_name from borrower b join loan l on l.loan_number=b.loan_number
order by customer_name;
+---------------+
| customer_name |
+---------------+
| renuka |
| srushti |
+---------------+
| branch_name | avg(amount) |
+-------------+-------------+
| akurdi | 12000.0000 |
| latur | 200000.0000 |
| loni | 40000.0000 |
| wagholi | 23000.0000 |
+-------------+-------------+
4 rows in set (0.02 sec)
+-------------+
| sum(amount) |
+-------------+
| 79000 |
+-------------+
1 row in set (0.00 sec)
10) Delete all loan with loan where amount between 13000 AND 15000
mysql> DELETE FROM loan WHERE amount BETWEEN 13000 AND 15000;
Query OK, 0 rows affected (0.01 sec)
+-------------+-------------+--------+
| loan_number | branch_name | amount |
+-------------+-------------+--------+
| 201 | akurdi | 23000 |
| 202 | latur | 56000 |
+-------------+-------------+--------+
2 rows in set (0.00 sec)