0% found this document useful (0 votes)
60 views7 pages

DBMS Case-2

Uploaded by

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

DBMS Case-2

Uploaded by

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

DBMS LAB-MANUAL- 2024-25

Case Study 2
Bank System - (group by, having clause) Database:
Create the following table and insert tuples with suitable constraints.

Table: Account Table: Branch

Account_No Cust_Name Brach_ID


AE0012856 Reena SB002
AE1185698 Akhil SB001
AE1203996 Daniel SB004
AE1225889 Roy SB002
AE8532166 Sowparnika SB003
AE8552266 Anil SB003
AE1003996 Saathwik SB004
AE1100996 Swarna SB002

Branch_ID Branch_Name Branch_City


SB001 Malleshwaram Bangalore
SB002 MG Road Bangalore
SB003 MG Road Mysore
SB004 Jayanagar Mysore

Table: Depositor Table: Loan


Account_No Branch_Id Balance Account_No Branch_Id Balance
AE0012856 SB002 12000 AE1185698 SB001 102000
AE1203996 SB004 58900 AE8552266 SB003 40000
AE8532166 SB003 40000 AE1003996 SB004 15000
AE1225889 SB002 150000 AE1100996 SB002 100000

create table Branch(


branch_id varchar(10) primary key,
branch_name char(20),
branch_city char(20)
);

Output:-

SSBCA COLLEGE GOKAK 1


DBMS LAB-MANUAL- 2024-25

create table Account(


account_no varchar(10) primary key,
cust_name char(20),
branch_id varchar(10) references Branch(branch_id)
);

Output:-

SSBCA COLLEGE GOKAK 2


DBMS LAB-MANUAL- 2024-25

create table Depositor (


account_no varchar (10) references Account(account_no),
branch_id varchar (10) references Branch(branch_id),
balance number (10,2)
);

Output: -

create table Loan (


account_no varchar (10) references Account(account_no),
branch_id varchar (10) references Branch(branch_id),
balance number (10,2)
);

Output: -

Insertion of Tuples into the above table is as follows:

1. insert into Branch values('SB001','Malleshwaram','Bangalore');

2. insert into Account values('AE0012856','Reena','SB002');

3. insert into Depositor values('AE0012856','SB002',12000);

4. insert into Loan values('AE1185698','SB001',102000);

To Display all the tuples from all the tables, the statement is,

Select * from Branch;


Output: -

SSBCA COLLEGE GOKAK 3


DBMS LAB-MANUAL- 2024-25

Select * from Account;


Output: -

Select * from Depositor;


Output: -

Select * from Loan;


Output: -

Solve the following queries for the above database: -


1. Display the Total Number of accounts present in each branch.
select b.branch_name, count(a.account_no) "Total_Accts"
from account a, branch b
where a.branch_id=b.branch_id
group by b.branch_name;
Output:-

2. Display the Total Loan amount in each branch.


select b.branch_name, sum(l.balance) "Tot_Loan_Amt"
from branch b, loan l
where b.branch_id=l.branch_id
group by b.branch_name;

SSBCA COLLEGE GOKAK 4


DBMS LAB-MANUAL- 2024-25

Output:-

3. Display the Total deposited amount in each branch by descending order.


select b.branch_name, sum(d.balance) "Tot_Deposit_Amt"
from branch b, Depositor d
where b.branch_id=d.branch_id
group by b.branch_name;

Output:-

4. Display max , min loan amount present in each city.


select b.branch_city, max(l.balance) "Max_LoanAmt", min(l.balance) "Min_LoanAmt"
from branch b, loan l
where b.branch_id=l.branch_id
group by b.branch_city;

Output:-

5. Display average amount deposited in each branch, each city.


select b.branch_city, avg(d.balance) "Average_Bal"
from branch b, Depositor d
where b.branch_id=d.branch_id
group by b.branch_city;

Output:-

SSBCA COLLEGE GOKAK 5


DBMS LAB-MANUAL- 2024-25

6. Display maximum of loan amount in each branch where the balance is more than 25000.
select b.branch_city, max(l.balance) "Max_loan_Amt"
from branch b, loan l
where l.branch_id=b.branch_id and l.balance in (select l.balance
from loan l, branch b
where l.balance>25000)
group by b.branch_city;

Output:-

7. Display Total Number of accounts present in each city.


select b.branch_city, count(account_no) "No_of_Accounts"
from account a, branch b
where a.branch_id=b.branch_id
group by b.branch_city;

Output:-

8. Display all customer details in ascending order of branch_id.


select a.branch_id, a.account_no, a.cust_name, b.branch_name, b.branch_city
from account a, branch b
where a.branch_id=b.branch_id
order by b.branch_id asc;

Output:-

SSBCA COLLEGE GOKAK 6


DBMS LAB-MANUAL- 2024-25

9. Update Balance to 26000 where account_no=AE1003996.


Before updating the values in the record are as shown the output

update loan
set balance=26000
where account_no='AE1003996';
Output:-

10. Display Customer Names with their branch Name


select cust_name, branch_name
from account a, branch b
where a.branch_id=b.branch_id;
Output:-

SSBCA COLLEGE GOKAK 7

You might also like