Sourabh Suresh Bandgar
Roll no:10
Experiment No. 7
Last login: Tue Oct 1 09:10:00 on console
(base) sourabhbandgar@Sourabhs-MacBook-Air ~ % mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 9.0.1 MySQL Community Server - GPL
Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights
reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input
statement.
mysql> create database Exp7;
Query OK, 1 row affected (0.04 sec)
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| Exp4 |
| Exp6 |
| Exp7 |
| information_schema |
| mysql |
| performance_schema |
| sourabh |
| sourabh2 |
| sys |
+--------------------+
9 rows in set (0.00 sec)
mysql> use Exp7;
Database changed
mysql> CREATE TABLE account (
-> account_number INT PRIMARY KEY,
-> branch_name VARCHAR(20),
-> balance int);
Query OK, 0 rows affected (0.02 sec)
mysql> INSERT INTO account (account_number, branch_name, balance)
VALUES
-> (101, 'Morewadi', 900000),
-> (102, 'phulewadi', 90000),
-> (105, 'Tandulwadi', 87000),
-> (109, 'Ambewadi', 46340),
-> (113, 'Punewadi', 2436660),
-> (118, 'Mumbawadi', 78770),
-> (120, 'DYPwadi', 53498573);
Query OK, 7 rows affected (0.01 sec)
Records: 7 Duplicates: 0 Warnings: 0
mysql> select * from account;
+----------------+-------------+----------+
| account_number | branch_name | balance |
+----------------+-------------+----------+
| 101 | Morewadi | 900000 |
| 102 | phulewadi | 90000 |
| 105 | Tandulwadi | 87000 |
| 109 | Ambewadi | 46340 |
| 113 | Punewadi | 2436660 |
| 118 | Mumbawadi | 78770 |
| 120 | DYPwadi | 53498573 |
+----------------+-------------+----------+
7 rows in set (0.00 sec)
mysql> CREATE TABLE depositor(customer_name varchar(20),
account_number int);
Query OK, 0 rows affected (0.01 sec)
mysql> INSERT INTO depositor(customer_name,account_number) VALUES
-> ('Rahul',101),
-> ('Narendra',102),
-> ('Arvind',105),
-> ('Mamata',109),
-> ('Akhilesh',113),
-> ('Uddhav',118),
-> ('Satej',120);
Query OK, 7 rows affected (0.01 sec)
Records: 7 Duplicates: 0 Warnings: 0
mysql> select * from depositor;
+---------------+----------------+
| customer_name | account_number |
+---------------+----------------+
| Rahul | 101 |
| Narendra | 102 |
| Arvind | 105 |
| Mamata | 109 |
| Akhilesh | 113 |
| Uddhav | 118 |
| Satej | 120 |
+---------------+----------------+
7 rows in set (0.01 sec)
mysql> CREATE TABLE borrower(
-> customer_name varchar(20),
-> loan_number int);
Query OK, 0 rows affected (0.01 sec)
mysql> insert into borrower VALUES
-> ('Narendra',2232),
-> ('Mamata',6765),
-> ('Satej',2435);
Query OK, 3 rows affected (0.00 sec)
Records: 3 Duplicates: 0 Warnings: 0
mysql> select * from borrower;
+---------------+-------------+
| customer_name | loan_number |
+---------------+-------------+
| Narendra | 2232 |
| Mamata | 6765 |
| Satej | 2435 |
+---------------+-------------+
3 rows in set (0.01 sec)
Q1)Find all customers having either loan, an account or both at the
bank.
mysql> select customer_name from depositor union select
customer_name from borrower;
+---------------+
| customer_name |
+---------------+
| Rahul |
| Narendra |
| Arvind |
| Mamata |
| Akhilesh |
| Uddhav |
| Satej |
+---------------+
7 rows in set (0.00 sec)
Q2)Find all customers having an account but not loan at the bank.
mysql> select customer_name from depositor where customer_name not
in(select customer_name from borrower);
+---------------+
| customer_name |
+---------------+
| Rahul |
| Arvind |
| Akhilesh |
| Uddhav |
+---------------+
4 rows in set (0.01 sec)
Q3)Find all customers having both an account and loan at the bank.
mysql> select customer_name from depositor where customer_name
in(select customer_name from borrower);
+---------------+
| customer_name |
+---------------+
| Narendra |
| Mamata |
| Satej |
+---------------+
3 rows in set (0.00 sec)
Q4)Find the customers who have balance more than 10000.
mysql> select depositor.customer_name,account_number,balance from
account natural join depositor where balance>10000;
+---------------+----------------+----------+
| customer_name | account_number | balance |
+---------------+----------------+----------+
| Rahul | 101 | 900000 |
| Narendra | 102 | 90000 |
| Arvind | 105 | 87000 |
| Mamata | 109 | 46340 |
| Akhilesh | 113 | 2436660 |
| Uddhav | 118 | 78770 |
| Satej | 120 | 53498573 |
+---------------+----------------+----------+
7 rows in set (0.00 sec)
Q5)List in alphabetic order, customers who have account at ‘DYPwadi’
branch.
mysql> select customer_name, account.account_number,
account.branch_name from depositor natural join account where
branch_name='Shahupuri' order by customer_name;
Empty set (0.01 sec)
mysql> select customer_name, account.account_number,
account.branch_name from depositor natural join account where
branch_name='DYPwadi' order by customer_name;
+---------------+----------------+-------------+
| customer_name | account_number | branch_name |
+---------------+----------------+-------------+
| Satej | 120 | DYPwadi |
+---------------+----------------+-------------+
1 row in set (0.00 sec)
Q6)Find all customers who have either an account or loan (but not
both) at the bank.
mysql> SELECT customer_name
-> FROM depositor
-> WHERE customer_name NOT IN (SELECT customer_name FROM
borrower)
-> UNION
-> SELECT customer_name
-> FROM borrower
-> WHERE customer_name NOT IN (SELECT customer_name FROM
depositor);
+---------------+
| customer_name |
+---------------+
| Rahul |
| Arvind |
| Akhilesh |
| Uddhav |
+---------------+
4 rows in set (0.00 sec)