DB 1 12
DB 1 12
1. Display customer name having living city Bombay and branch city Nagpur
2. Display customer name having same living city as their branch city
3. Display customer name who are borrowers as well as depositors and having
living city Nagpur.
4. Display borrower names having deposit amount greater than 1000 and loan
amount greater than 2000
5. Display customer name living in the city where branch of depositor sunil is
located.
6. Create an index on deposit table
___________________________________________________________________________________
_____________________________________________________________
create database 12Practical;
use 12Practical;
1. Display customer name having living city Bombay and branch city Nagpur
SELECT c.cname
FROM Customers c
JOIN Deposit d ON c.cname = d.cname
JOIN Branch b ON d.bname = b.bname
WHERE c.city = 'Bombay' AND b.city = 'Nagpur';
Empty set (0.00 sec)
(Based on the sample data provided earlier, no record meets the condition where a
customer in Bombay has a deposit in a Nagpur branch.)
2. Display customer name having same living city as their branch city
SELECT c.cname
FROM Customers c
JOIN Deposit d ON c.cname = d.cname
JOIN Branch b ON d.bname = b.bname
WHERE c.city = b.city;
+-------+
| cname |
+-------+
| Anil |
| Sunil |
| Ravi |
+-------+
3. Display customer name who are borrowers as well as depositors and having
living city Nagpur.
SELECT c.cname
FROM Customers c
JOIN Deposit d ON c.cname = d.cname
JOIN Borrow b ON c.cname = b.cname
WHERE c.city = 'Nagpur';
+-------+
| cname |
+-------+
| Sunil |
+-------+
4. Display borrower names having deposit amount greater than 1000 and loan
amount greater than 2000
+-------+
| cname |
+-------+
| Anil |
| Sunil |
+-------+
5. Display customer name living in the city where branch of depositor sunil is
located.
SELECT c.cname
FROM Customers c
JOIN Deposit d1 ON c.cname = d1.cname
JOIN Branch b1 ON d1.bname = b1.bname
JOIN Deposit d2 ON d2.cname = 'Sunil'
JOIN Branch b2 ON d2.bname = b2.bname
WHERE c.city = b2.city;
+-------+
| cname |
+-------+
| Sunil |
+-------+