Freelancer management system (1)
Freelancer management system (1)
Introduction to Database
Scenerio
Each seller has a unique seller id, seller name, phone number and multiple skill.
In a Freelancer website Management system Buyer has a unique buyer id, a buyer city,
country and multiple phone number. Multiple buyer works freelancer website with
seller. Each seller has a unique seller id, seller name, phone number and multiple skill.
(freelancer, buyer & seller where all these relations are many to many relation).
Each multiple seller contest each to another client. It has a unique id, email, tips and
name.
In a Freelancer website Management system Buyer has a unique buyer id, a buyer city,
country and multiple phone number. Multiple buyer works freelancer website with
seller. Each seller has a unique seller id, seller name, phone number and multiple skill.
Each multiple seller contest each to another client. It has a unique client id, email, tips
and name ( seller, contest & client where all these relations are one to many relation).
Each buyer order relation by each Payment. Payment has a payment amount, payment date and payment
unique id (primary key).
Freelancer ( B_id , B_name , city , country , B_phone , S_id , S_name , S_phone , skill )
1NF: B_phone , skill are multivalued
2NF: B_id , B_name , city , country , B_phone
S_id , S_name , S_phone , skill
3NF: B_id , B_name ,B_phone
L_id , city , country
S_id , S_name , S_phone , skill
Table for Freelancer:
1. B_id , B_name , L_id , S_id
2. L_id , city , country
3. S_id , S_name , S_phone
4. B_id , B_phone
5. S_id , skill
Final Table:
1. B_id , B_name , L_id , S_id
2. L_id , city , country
3. S_id , S_name , S_phone
4. B_id , B_phone
5. S_id , skill
6. B_id , B_name , E_id , P_id
7. E_id , city , country
8. P_id , P_amount , P_date
9. S_id , S_name , S_phone , C_id
10. C_id , C_name , tips
11. C_id, Email
Create Table
create table byer(
b_id number(12) primary key,
b_name varchar2(18),
l_id number(12),
s_id number(12))
alter table byer add constraint ax1 foreign key(l_id)references bio_byer(l_id)
alter table byer add constraint ax2 foreign key(s_id)references seller(s_id)
Data Insertion
insert into byer values(1001,'Alif',2001,3001)
insert into byer values(1002,'Rana',2002,3002)
insert into byer values(1003,'Fariad',2003,3003)
insert into byer values(1004,'Niloy',2004,3004)
Subquery
1. Display all id, amount & date from payment where payment amount is equal to maximum
amount.
select p_id, p_amount, p_date
from payment
where p_amount in (select max(p_amount) from payment)
2. Display all id, name & tips from client where tips is equal to minimum tips.
select c_id, c_name, tips
from client
where tips = (select min(tips) from client)
3. Display all id, name, phone number & date from seller2 where seller name is related to
client id=7002.
select s_id, s_name, s_phone, c_id
from seller2
where s_name = (select s_name from seller2 where c_id=7002)
4. Display all b_id, name & l_id, s_id from byer where byer name is related to byer id=1003.
select b_id, b_name, l_id, s_id
from byer
where b_name in (select b_name from byer where b_id=1003)
Joining
5. Get all byer id, name & country from both tables byer_1 & bio_byer1 and city in Dhaka.
select b_id,b_name,country
from byer_1,bio_byer1
where byer_1.e_id(+)=bio_byer1.e_id and city='Dhaka'
6. Select seller name, id & byer name from byer & seller tables who has seller id=3001.
select s_name,b_name,byer.s_id
from byer,seller
where byer.s_id=seller.s_id
and byer.s_id=3001
7. Select seller id, name & client id where seller has the phone number= 1925346927.
select a.s_id,b.s_name,b.c_id
from seller2 a, seller2 b
where a.s_id=b.s_id and a.s_phone=1925346927
View
8. Create a view called test_view based on payment id, payment amount from payment table
where payment amount is equal to minimum amount.
create view test_view
(name, min_amount)
as select b.p_id, MIN(p.p_amount)
from payment b, payment p
where b.p_id = p.p_id
group by b.p_id