0% found this document useful (0 votes)
105 views4 pages

2

The document contains SQL queries and results from interacting with a MySQL database called "bank". It creates a table called "bank" with fields for account number, customer name, bank name, amount, date opened, and number of transactions. It then inserts 9 records into the table and runs various SELECT queries to retrieve, filter, aggregate and order the data in the table.

Uploaded by

roitnehra
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
105 views4 pages

2

The document contains SQL queries and results from interacting with a MySQL database called "bank". It creates a table called "bank" with fields for account number, customer name, bank name, amount, date opened, and number of transactions. It then inserts 9 records into the table and runs various SELECT queries to retrieve, filter, aggregate and order the data in the table.

Uploaded by

roitnehra
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 4

Enter password:*****

Welcome to the MySQL monitor. Commands end with ; or \g.


Your MySQL connection id is 1
Server version: 5.1.33-community MySQL Community Server (GPL)
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql> use bank;
Database changed
mysql> create table bank
-> (Acc_no int,
-> CName char(15) not null primary key,
-> BName char(20),
-> Amount int,
-> DateofOpen date,
-> T_Transactions int);
Query OK, 0 rows affected (1.64 sec)
mysql> insert into bank
-> values(1,'Karan','Bank of Baroda',15000,'1998-01-12',10);
Query OK, 1 row affected (0.13 sec)
mysql> insert into bank
-> values(2,'Puneet','State Bank',25000,'1997-02-01',09);
Query OK, 1 row affected (0.07 sec)
mysql> insert into bank
-> values(3,'Anirban','Oriental Bank',17000,'1999-07-15',05);
Query OK, 1 row affected (0.08 sec)
mysql> insert into bank
-> values(4,'Yatin','Standard Chartered',38000,'1999-02-10',11);
Query OK, 1 row affected (0.04 sec)
mysql> insert into bank
-> values(5,'Sunny','State Bank',47000,'1998-02-06',15);
Query OK, 1 row affected (0.07 sec)
mysql> insert into bank
-> values(6,'Jayant','UCO Bank',34000,'1998-08-10',07);
Query OK, 1 row affected (0.37 sec)
mysql> insert into bank
-> values(7,'Nikhil','Bank of Baroda',56000,'1999-01-02',12);
Query OK, 1 row affected (0.04 sec)
mysql> insert into bank
-> values(8,'Tarun','Oriental Bank',22000,'1999-04-04',08);
Query OK, 1 row affected (0.08 sec)
mysql> insert into bank
-> values(9,'Jisha','UCO Bank',34500,'1998-01-05',11);
Query OK, 1 row affected (0.07 sec)
mysql> select * from bank;
+--------+---------+--------------------+--------+------------+----------------+
| Acc_no | CName | BName
| Amount | DateofOpen | T_Transactions |
+--------+---------+--------------------+--------+------------+----------------+
|

1 | Karan

| Bank of Baroda

| 15000 | 1998-01-12 |

10 |

2 | Puneet | State Bank

| 25000 | 1997-02-01 |

9 |

3 | Anirban | Oriental Bank

| 17000 | 1999-07-15 |

5 |

4 | Yatin

| Standard Chartered | 38000 | 1999-02-10 |

11 |

5 | Sunny

| State Bank

| 47000 | 1998-02-06 |

15 |

6 | Jayant | UCO Bank

| 34000 | 1998-08-10 |

7 |

7 | Nikhil | Bank of Baroda

| 56000 | 1999-01-02 |

12 |

8 | Tarun

| Oriental Bank

| 22000 | 1999-04-04 |

8 |

9 | Jisha

| UCO Bank

| 34500 | 1998-01-05 |

11 |

+--------+---------+--------------------+--------+------------+----------------+
9 rows in set (0.11 sec)
A)
mysql> select * from bank
-> where t_transactions between 8 and 11;
+--------+--------+--------------------+--------+------------+----------------+
| Acc_no | CName | BName
| Amount | DateofOpen | T_Transactions |
+--------+--------+--------------------+--------+------------+----------------+
|
1 | Karan | Bank of Baroda
| 15000 | 1998-01-12 |
10 |
|

2 | Puneet | State Bank

| 25000 | 1997-02-01 |

9 |

4 | Yatin | Standard Chartered | 38000 | 1999-02-10 |

11 |

8 | Tarun | Oriental Bank

| 22000 | 1999-04-04 |

8 |

9 | Jisha | UCO Bank

| 34500 | 1998-01-05 |

11 |

+--------+--------+--------------------+--------+------------+----------------+
5 rows in set (0.28 sec)
B)
mysql> select * from bank
-> order by dateofopen;
+--------+---------+--------------------+--------+------------+----------------+
| Acc_no | CName | BName
| Amount | DateofOpen | T_Transactions |
+--------+---------+--------------------+--------+------------+----------------+
|

2 | Puneet | State Bank

| 25000 | 1997-02-01 |

9 |

9 | Jisha

| UCO Bank

| 34500 | 1998-01-05 |

11 |

1 | Karan

| Bank of Baroda

| 15000 | 1998-01-12 |

10 |

5 | Sunny

| State Bank

| 47000 | 1998-02-06 |

15 |

6 | Jayant | UCO Bank

| 34000 | 1998-08-10 |

7 |

7 | Nikhil | Bank of Baroda

| 56000 | 1999-01-02 |

12 |

4 | Yatin

| Standard Chartered | 38000 | 1999-02-10 |

11 |

8 | Tarun

| Oriental Bank

| 22000 | 1999-04-04 |

8 |

3 | Anirban | Oriental Bank

| 17000 | 1999-07-15 |

5 |

+--------+---------+--------------------+--------+------------+----------------+
9 rows in set (0.06 sec)
C)
mysql> select count(cname) from bank
-> where amount<30000;
+--------------+
| count(cname) |
+--------------+
|
4 |
+--------------+
1 row in set (0.37 sec)
D)
mysql> select max(amount),min(amount) from bank;
+-------------+-------------+
| max(amount) | min(amount) |
+-------------+-------------+
|
56000 |
15000 |
+-------------+-------------+
1 row in set (0.00 sec)
E)
mysql> select cname,bname,amount from bank
-> where amount <20000;
+---------+----------------+--------+
| cname | bname
| amount |
+---------+----------------+--------+
| Karan | Bank of Baroda | 15000 |
| Anirban | Oriental Bank | 17000 |
+---------+----------------+--------+
2 rows in set (0.00 sec)
F)
mysql> select acc_no,cname,bname,t_transactions from bank
-> order by amount desc;
+--------+---------+--------------------+----------------+
| acc_no | cname | bname
| t_transactions |
+--------+---------+--------------------+----------------+
|
7 | Nikhil | Bank of Baroda
|
12 |
|
5 | Sunny | State Bank
|
15 |
|
4 | Yatin | Standard Chartered |
11 |
|
9 | Jisha | UCO Bank
|
11 |
|
6 | Jayant | UCO Bank
|
7 |
|
2 | Puneet | State Bank
|
9 |
|
8 | Tarun | Oriental Bank
|
8 |
|
3 | Anirban | Oriental Bank
|
5 |
|
1 | Karan | Bank of Baroda
|
10 |
+--------+---------+--------------------+----------------+
9 rows in set (0.00 sec)

G)
mysql> select avg(amount) from bank where amount<23000;
+-------------+
| avg(amount) |
+-------------+
| 18000.0000 |
+-------------+
1 row in set (0.08 sec)
mysql> select max(amount) from bank where amount>30000;
+-------------+
| max(amount) |
+-------------+
|
56000 |
+-------------+
1 row in set (0.00 sec)
mysql> select sum(t_transactions) from bank;
+---------------------+
| sum(t_transactions) |
+---------------------+
|
88 |
+---------------------+
1 row in set (0.00 sec)
mysql> select count(distinct bname) from bank;
+-----------------------+
| count(distinct bname) |
+-----------------------+
|
5 |
+-----------------------+
1 row in set (0.05 sec)

You might also like