Bank Account Database
Bank (Id_bank, name, location)
Client (clt_id, name, dob, address, phone)
Account(account_nb, creation_date, amount, type, #clt_id, #id_bnk)
1- Base On the relational schema above, Create the database and the
tables and insert the values
create database bankAccount;
use bankAccount;
create table Bank(
id_bank integer primary key,
name varchar(20) unique not null,
location varchar(20)
);
insert into Bank values
(10, 'BLC', 'Tell'),
(20, 'BLOM', 'Azmi'),
(30, 'Fransabank', 'Akkar'),
(40, 'BBC', 'Tell');
create table client(
id_clt int primary key auto_increment,
name varchar(20) not null,
dob date,
address varchar(50),
phone varchar(10)
);
1
insert into client(dob, name, address, phone) values
('1990-01-10', 'samir', 'Tripoli', '76-112112'),
('1992-03-15', 'samira', 'Akkar', '76-321123'),
('1991-04-12', 'amir', 'Tripoli', '76-212112'),
('1995-02-16', 'amira', 'Tripoli', '76-552112'),
('1996-11-11', 'mounir', 'Saida', '70-112112'),
('1992-05-10', 'mounira', 'Alma', '71-112112');
create table Account(
account_nb int primary key,
creation_date date,
amount double(10,1),
type varchar(10),
clt_id int references client(id_clt),
id_bnk int,
foreign key (id_bnk) references Bank(id_bank)
);
insert into Account values
(1001, '2020-11-12', 1000.5, 'debit', 1, 10),
(1002, '2022-10-10', 500.3, 'online', 1, 20),
(1003, '2020-11-12', 5000.5, 'debit', 1, 10),
(1004, '2022-11-11', 700.5, 'credit', 2, 30),
(1005, '2020-11-12', 1000.5, 'debit', 1, 10);
2
1- List all bank accounts
Select * from account
2- List all account number where the amount under 1000
Select account_nb
From account
Where amount<1000;
3- List all creation date of accounts sorted by older
Select creation_date
From account
Order by 1;
4- List the account number sorted by amount descending then
account number ascending
Select account_nb, amount
From account
Order by 2 desc, 1 desc;
5- List all accounts of debit type
Select * from account where type=’debit’
6- List all accounts of debit type or amount between 500 and
1000
Select *
from account
where type=’debit’
or amount between 500 and 1000
3
7- List all client name begin by ‘s’
Select name
from client
where name like ‘s%’
8- List all clients where name end by ‘ir’ or ‘ira’
Select *
from client
where name like ‘%ir’ or name like ‘%ira’;
9- List all clients where name contains ’am’
Select *
from client
where name like ‘%am%’;
10- List all bank locations (without redundancy)
Select distinct location
from bank;
11- List all account numbers for ‘samir’
select account_nb
from account
where clt_id in
(select id_clt
from client
where name='samir');
4
12- List all account number and amount for BLC bank
Select account_nb
From account
Where id_bnk =
(Select id_bank
from bank
where name=’BLC’)
13- List the names and ages of all clients
Select name, 2024-Year(dob) as age
from client
order by age desc ;
14- List all bank names where location in tell or azmi
Select name
from bank
where location in (‘tell’, ‘azmi’);
15- List all accounts number and amount of ‘samir’ in ‘BLC’ bank
only
Select account_nb, amount
from account
where clt_id =
(Select id_clt from client where name='samir')
and id_bnk =
(Select id_bank from bank where name='BLC');