Relational ALgebra (Summer+Spring-2021)

Download as pdf or txt
Download as pdf or txt
You are on page 1of 19

What‌‌is‌‌Relational‌‌Algebra(DDL)?

‌ 
‌Solution:‌ 
  Relational‌‌ algebra‌‌ is‌‌ a ‌‌procedural‌‌ query‌‌ language,‌‌ which‌‌ takes‌ 
instances‌  ‌of‌  ‌relations‌  ‌as‌  ‌input‌  ‌and‌  ‌yields‌  ‌instances‌  ‌of‌  ‌relations‌  ‌as‌ 
output.‌‌   It‌‌
  uses‌‌
  operators‌‌  to‌‌  perform‌‌ queries.‌‌ An‌‌ operator‌‌ can‌‌ be‌‌ either‌ 
unary‌‌or‌‌binary.‌ 
 
‌The‌‌fundamental‌‌o perations‌‌o f‌‌relational‌‌a lgebra‌‌a re‌‌a s‌‌follows‌‌−‌ 
● Select(ROW)‌ 
● Project(COLUMN)‌ 
● Union‌ 
● Set‌‌different‌ 
● Cartesian‌‌product‌ 
● Rename‌ 

Example‌‌Table:‌ 
Customer(Customer_name,‌Customer_Id‌,Cus‌
tomer_city,Customer_street,Total_Bill,Date)‌ 
Depositor(Customer_name,Branch_name,‌Ac‌
count_number‌,amount);‌ 
Borrower(Customer_name,amount,C_d,C-S)‌
;‌ 
 
‌CUSTOMER‌‌TABLE‌ 
 
Customer_‌ Customer_I‌ Customer_‌ Customer_s‌ Total_Bill‌  Date‌ 
Name‌  d‌  City‌  treet‌ 

Jhon‌  102‌  Brooklyn‌  Senator‌  100‌  15/1/2021‌ 

Peter‌  111‌  Berlin‌  311F‌  120‌  2/1/2020‌ 

Annie‌  105‌  Montreal‌  T221‌  250‌  3/1/2021‌ 

Marie‌  601‌  Berlin‌  GH344‌  1000‌  7/2/2021‌ 

Alice‌  502‌  Virginia‌  HP122‌  540‌  11/2/2021‌ 

Bob‌  304‌  New‌‌York‌  JKM450‌  600‌  15/2/2021‌ 

Kourtney‌  612‌  Quebec‌  34B‌  650‌  17/1/2021‌ 

Kim‌  311‌  Baltimore‌  21B‌  780‌  9/2/2021‌ 

Jane‌  213‌  Montreal‌  TY20‌  290‌  18/1/2021‌ 

Rafael‌  214‌  Miami‌  3E420‌  340‌  29/1/2021‌ 

1.Find‌‌out‌‌the‌‌information‌‌‌of‌‌the‌‌customer‌‌who‌ 
has‌‌shopped‌‌in‌‌this‌‌present‌‌year‌‌‌from‌‌the‌‌shop.‌ 
‌Select‌‌*‌‌from‌‌Customer‌  
‌ here‌‌Date‌ ‌BETWEEN‌‌1/1/2021‌‌AND‌ 
W
31/12/2021;‌ 
‌𝛔 ‌ Date>=1/1/2021 OR Date<=31/12/2021(Customer) ;‌  ‌

‌𝛔 ‌ ′1/1/2021′<=Date<=′31/12/2021′ (Customer)   ‌
 

Select‌‌Operation‌‌(σ):‌ 

Notation‌‌−‌‌ 𝛔‌ P (r) ;‌  ‌


Operator:‌  
1‌ .AND,OR,NOT‌ 
‌2.‌‌Equal:‌‌=‌‌,‌ 
‌Greater‌‌Than:‌‌>‌‌,‌ 
‌Less‌‌Than‌‌:‌‌<‌‌,‌ 
‌Less‌‌Than‌‌Equal:‌‌<=‌‌OR‌‌≤‌,‌ 
‌Greater‌‌Than‌‌Equal:‌‌>=‌‌OR‌‌≥‌‌,‌ 
‌Not‌‌Equal:‌ ‌<>‌‌OR‌‌!=‌ 
1.SHOW‌‌THE‌‌INFORMATION‌‌‌OF‌‌THE‌‌CUSTOMER‌ 
LIVING‌‌IN‌‌“BROOKLYN”‌‌‌CITY.‌ 
‌SELECT‌‌*‌‌FROM‌ ‌Customer‌‌WHERE‌‌Customer_city=‌ 
‘BROOKLYN’;‌ 
𝛔‌ Customer−city= ′Brooklyn′  (Customer) ;‌  ‌

2.Show‌‌the‌‌information‌‌‌of‌‌the‌‌customer‌ 
living‌‌in‌‌‌Senator‌‌street‌‌of‌‌Brooklyn‌.‌ 
Select‌‌* ‌‌from‌‌c ustomer‌‌WHERE‌‌Customer_City=‌‌‘Brooklyn’‌‌AND‌ 
Customer_Street=‌‌‘Senator’;‌ 

‌ ‌𝛔‌ Customer−city= ′Brook lyn′ AN D Customer−Street= ′Senator′  (Customer) ‌; ‌ ‌


 
1.Find‌‌out‌‌the‌‌customers‌‌who‌‌live‌‌in‌‌Montreal.‌ 
‌Select‌‌*‌‌from‌‌customer‌‌where‌‌Customer_City=‌‌‘Montreal’;‌ 
𝛔‌ Customer−City= ′Montreal′(Customer);   ‌

2.Find‌‌out‌‌the‌‌customer‌‌information‌‌who‌ 
lives‌‌in‌‌GH344,Berlin.‌ 
‌Select‌‌*‌‌from‌‌Customer‌‌Where‌‌Customer_City=‌‌‘Berlin’‌‌AND‌ 
Customer_Street=‌‌‘GH344’;‌ 
𝛔‌ C ustomer−C ity= ′Berlin′ AN D C ustomer−Street=′GH 344′(Customer);   ‌
3.Find‌‌out‌‌the‌‌customer‌‌information‌‌who‌‌lives‌‌either‌ 
in‌‌New‌‌York‌‌Or‌‌Quebec.‌ 
‌ elect‌‌*‌‌from‌‌customer‌‌Where‌‌Customer_City=‌‌‘New‌‌York’‌ 
S
OR‌‌‘Quebec’;‌ 
𝛔‌ C ustomer−C ity= ′N ew Y ork′ OR ′Quebec′(Customer);   ‌
4.Find‌‌out‌‌the‌‌information‌‌of‌‌the‌‌customers‌‌whose‌ 
customerId‌‌is‌ ‌more‌‌than‌‌200.‌ 
‌𝛔 ‌ C ustomer−id >200 (Customer);   ‌
5.Find‌‌out‌‌the‌‌customer‌‌information‌‌whose‌‌customer‌ 
Id‌‌is‌‌in‌‌between‌‌100‌‌and‌‌600.‌ 
‌100<=Customer_Id<=600‌ 
‌20<=Age<=25‌ 
‌𝛔 ‌ 100<=C ustomer−id <=600 (Customer);   ‌
‌6.Find‌‌out‌‌the‌‌customer's‌‌name‌‌‌who‌‌has‌‌done‌‌more‌ 
than‌‌200$‌‌Shopping‌ ‌from‌‌the‌‌shop.‌ 
‌Select‌‌Customer_Name‌‌‌from‌‌customer‌‌where‌ 
Total_bill>200;‌ 
π‌ Customer −N ame,T otal −Bill>200   (Customer);   ‌
𝛔‌ T otal−Bill>200 (Customer);   ‌
π‌ Customer −N ame  (�� T otal −Bill>200 (Customer));
 ‌  
 
 
 
 

Project‌‌Operation‌‌(∏):‌ 
 

Notation:‌ π‌ P     (r);  ‌

1.Show‌‌the‌‌names‌‌of‌‌the‌‌customers.‌ 
‌π‌ Customer−name    (Customer);   ‌
2.Show‌‌the‌‌name‌‌&‌‌city‌ ‌of‌‌the‌‌customers.‌ 

‌π‌ Customer−name,Customer−city    (Customer);
   
1.Find‌‌out‌‌the‌‌Total_Bill‌‌‌of‌‌all‌‌the‌‌customers‌‌in‌‌the‌‌customer‌ 
table.‌ 
‌Select‌‌Total_bill‌‌from‌‌Customer;‌ 

‌ π‌ T otal −Bill   (Customer);   ‌
2.‌Find‌‌out‌‌the‌‌Total_Bill‌‌with‌‌the‌‌customer's‌‌‌name‌‌from‌‌the‌ 
customer‌‌table.‌ 
Select‌‌Customer_name,Total_Bill‌‌from‌‌Customer;‌ 
π‌ T otal−Bill,Customer−Name   (Customer);   ‌
π‌ T otal −Bill,Customer −N ame,Customer −city   (Customer);   ‌
π‌
 T otal−Bill,Customer−N ame,Customer−city,Customer−Address   (Customer);   ‌
 
 
3.Find‌‌out‌‌the‌‌Customer’s‌‌Bill‌‌‌which‌‌is‌‌more‌‌than‌‌200$‌.‌ 
‌π‌ T otal−Bill>200   (Customer);   ‌
4.Find‌‌out‌‌the‌‌Customer's‌‌city‌‌‌either‌‌in‌‌Berlin‌‌or‌‌Brooklyn‌.‌ 
‌π‌ Customer−city=′Berlin′ OR ′Brooklyn′   (Customer);   ‌
5.Find‌‌out‌‌the‌‌Id‌‌of‌‌the‌‌customer‌‌which‌‌is‌‌in‌ 
between‌‌400‌‌to‌‌120.‌ 
π‌ 120<=Id<=400   (Customer);   ‌
5.Find‌‌out‌‌the‌‌Customer’s‌‌Name,Customer_Id‌‌‌Whose‌ ‌bill‌‌‌is‌ 
within‌‌200‌‌to‌‌1000‌‌with‌‌the‌‌city‌‌in‌‌“Brooklyn”‌‌or‌‌“Berlin”.‌ 
 
π‌ Customer−N ame,Customer−id   (   ‌
 �� (200<=T otal−Bill<=1000) AN D (Customer−City=′Brooklyn′ OR ′Berlin′)
 
SELECT‌‌Customer_Name(PROJECT)‌‌‌from‌‌Customer‌ 
‌WHERE‌‌Total_bill(SELECT)‌‌‌BETWEEN‌‌200‌‌AND‌‌400;‌ 
(PROJECT+SELECT)‌ 
 
SELECT‌‌Total_Bill‌‌‌from‌‌Customer‌ 
WHERE‌‌Total_bill‌‌‌BETWEEN‌‌200‌‌AND‌‌400;(PROJECT)‌ 
  
‌π‌ 200<=T otal−Bill<=1000   (Customer);    ‌ ‌
     
π‌ Customer−N ame   (�� 200<=T otal−Bill<=1000 (Customer));
6.Find‌‌out‌‌the‌‌Customer’s‌‌Name‌‌&‌ 
Customer‌‌Id‌‌‌Whose‌ ‌bill‌‌within‌‌200‌‌to‌‌1000.‌ 
‌π‌ Customer−Name,Customer−Id  (�� 200<=T otal−Bill<=1000 (Customer));
 ‌  
 
 
Class‌‌Work:‌ 
‌‌1.Find‌‌out‌‌the‌‌customer’s‌‌Name‌‌&‌‌Address‌‌who‌‌has‌ 
shopped‌‌more‌‌than‌‌300$‌‌‌in‌‌the‌‌previous‌‌month‌‌‌&‌‌lives‌‌either‌ 
in‌‌Brooklyn‌‌or‌‌Miami‌.‌ 
 
2.The‌‌Super‌‌shop‌‌in‌‌florida‌‌wants‌‌a‌‌survey‌‌on‌‌the‌‌regular‌ 
customer’s‌‌list‌‌to‌‌find‌‌out‌‌the‌‌customer's‌‌Id,Name‌‌&‌‌Address‌ 
who‌‌has‌‌a‌‌total‌‌bill‌‌less‌‌than‌‌500$‌‌and‌‌lives‌ ‌nearby‌   
the‌‌shop‌‌and‌‌write‌‌the‌‌output‌‌from‌‌the‌‌table‌‌with‌‌SQL‌‌&‌ 
Relational‌‌Algebra.‌ 
 
CLASS‌‌WORK(20/2/2021):‌ 

 
1.Find‌‌out‌‌the‌‌employee‌‌name‌‌who‌‌has‌‌the‌ 
maximum‌‌salary.‌ 
‌‌SELECT‌‌Employee_Name‌‌FROM‌‌Customer‌‌WHERE‌ 
Employee-salary‌‌IN(SELECT‌‌MAX(Employee_salary)‌‌from‌‌Customer);‌ 

π‌ Employee−name (��  (Customer)) ;
‌??‌   ‌
1.Find‌‌out‌‌the‌‌Employee‌‌Name‌‌who‌‌are‌‌living‌‌in‌‌the‌‌same‌‌country.‌ 
SQL:‌ 
‌Select‌‌Employee_Name‌‌from‌‌e mployee‌ 
‌Group‌‌BY‌‌Country;‌ 
Instance‌ 
Relational‌‌Algebra:‌ 

‌π‌ Employee−name (�� A.Country=B.Country (Customer)) ;
 ‌  

‌π‌ Employee−N ame   (�� Country=′Bangladesh′ AN D Country=′Germany′(Customer));


   
OUTPUT:‌ 
‌Jidan‌ 
‌Albin‌ 
‌Marjea‌ 
‌Prince‌ 
‌Shama‌ 
    
   
2.Find‌‌out‌‌the‌‌Employee‌‌Salary‌‌who‌‌are‌‌in‌‌the‌‌age‌‌group‌‌of‌‌20‌‌to‌‌30.‌ 
SQL:‌ 
‌Select‌‌e mployee_salary‌‌from‌‌e mployee‌‌WHERE‌  
‌Age‌‌BETWEEN‌‌20‌‌AND‌‌30;‌ 
R.A:‌ 
‌ ‌π‌ Employee−salary  (�� 20<=Age<=30(Employee));  ‌  
3.Find‌‌out‌‌the‌‌Name‌‌of‌‌the‌‌e mployee‌‌living‌‌in‌‌Germany.‌ 
SQL:‌ 
‌Select‌‌Employee_name‌‌from‌‌Employee‌ 
‌WHERE‌‌Country=‌‌‘Germany’;‌ 
R.A:‌ 
‌ ‌ Employee−name  (�� Country=′Germany ′ (Employee));
π  ‌  
 
4.Find‌‌out‌‌the‌‌Salary‌‌of‌‌the‌‌e mployees‌‌living‌‌in‌‌Munich‌‌and‌‌an‌‌age‌‌group‌ 
between‌‌20‌‌to‌‌25.‌ 
‌R.A:‌ 
‌ ‌π‌ Employee−salary  (�� City=′M unich′ AN D 20<=Age<=25 (Employee));
 ‌  
5.Find‌‌out‌‌the‌‌age‌‌of‌‌the‌‌e mployees‌‌living‌‌in‌‌Bangladesh‌‌having‌‌salary‌‌in‌ 
1200,2500,1350.‌ 

π‌

 Age (�� Country=′Bangladesh′ AND Employee−salary=1200 OR Employee−salary=1200 OR Employee−salary=1200  (Employee));
 ‌  
6.Find‌‌out‌‌the‌‌e mployees‌ ‌e ither‌‌living‌‌in‌‌Bangladesh‌‌or‌‌Germany‌‌and‌ 
having‌‌age‌‌not‌‌more‌‌than‌‌35.‌ 
‌𝛔 ‌ C ountry=′Bangladesh ′ OR ′Germany′ AN D Age <=35 (Employee);    ‌ ‌
7.Find‌‌out‌‌the‌‌e mployees‌‌e ither‌‌living‌‌in‌‌Bangladesh‌‌and‌‌Germany‌‌or‌ 
having‌‌age‌‌not‌‌more‌‌than‌‌35.‌ 
𝛔‌ C ountry=′Bangladesh′ AN D ′Germany′ OR Age <=35 (Employee);   ‌ ‌
8.Find‌‌out‌‌the‌‌e mployee‌‌information‌‌who‌‌does‌‌live‌‌in‌‌Bangladesh‌‌or‌‌USA.‌ 
‌𝛔 ‌ C ountry=′Bangladesh ′ OR ′U SA′  (Employee);   ‌ ‌

MID‌‌TERM‌‌ENDS‌ 
 

UNION:‌ 
A={1,2,3},B={a,b,3}‌ 
A‌‌-‌‌B=‌‌{1,2}‌ 
B‌‌-‌‌A‌‌=‌‌{a,b}‌ 
A‌‌U‌‌B={1,2,3,a,b}‌ 
B‌‌U‌‌A‌‌=‌‌{1,2,3,a,b}‌ 
A‌‌∩‌‌B=‌‌{3}‌ 
B‌‌∩‌‌A=‌‌{3}‌ 
A‌‌X‌‌B‌‌={(1,a),(2,a),(3,a),(1,b),(2,b),(3,b),(1,3),(2,3),(3,3)}‌ 
 
 
 
Customer(Customer_name,‌Customer_Id‌,Customer_‌
city,Customer_street,Total_Bill,Date)‌ 
Depositor‌(Customer_name,Branch_name,‌Account_n‌
umber‌,amount);‌ 
Borrower‌(Customer_name,amount,C_d,C-S);‌ 
   
1.Find‌‌the‌‌names‌‌of‌‌customers‌‌who‌‌have‌‌an‌‌account‌‌with‌‌the‌ 
bank.‌ 
‌π‌ Customer −name    (Customer) ‌∩ ‌ ‌
‌π‌ Customer −name    (Depositor);   ‌
2.Find‌‌the‌‌name‌‌of‌‌the‌‌customer‌‌who‌‌has‌‌a‌‌loan.‌ 
πCustomer −name    (Customer) ‌∩  ‌‌ ‌
‌π‌ Customer −name    (Borrower);   ‌
3.Find‌‌the‌‌name‌‌of‌‌the‌‌customers‌‌who‌‌have‌‌either‌‌a‌‌loan‌‌or‌ 
an‌‌account‌‌or‌‌both.‌ 
‌πCustomer −name    (Depositor) ‌U  ‌‌ ‌
‌π‌ Customer −name    (Borrower);   ‌
4.Find‌‌the‌‌name‌‌of‌‌the‌‌customer‌‌who‌‌has‌‌only‌‌a‌‌deposit‌ 
account.‌ 
‌(‌ ‌π‌ ‌ Customer −name    (Customer) ∩‌  ‌
‌π‌ Customer −name    (Depositor) )‌‌- ‌ ‌
‌π‌ Customer −name    (Borrower);   ‌
 
 
Anna,Carl,Penny,Jenny.Marco,Jacob(Customer)‌ 
Carl‌,‌Penny‌,Jacob,Jenny(Depositor)‌ 
Anna,Marco,‌Carl‌,‌Penny‌(Borrower)‌ 
OUTPUT:‌ 
‌Jacob,Jenny‌ 
Customer(Cust_id,Cust_Name)‌ 
Account(Cust_id,Branch)‌ 
Loan(Cust_id,Branch)‌ 
‌1‌‌A‌ ‌2‌‌New‌‌York‌ 
‌2‌‌B‌ ‌2‌‌Berlin‌ 
‌3‌‌C‌ ‌3‌‌Virginia‌ 
OUTPUT:‌‌B‌ 
i)‌‌Cartesian‌‌Product(Cust_id)‌ 
ii)Select‌‌New‌‌York‌ 
iii)‌‌Project‌‌Customer_Name‌ 
 
5.Find‌‌out‌‌the‌‌name‌‌of‌‌the‌‌customers‌‌who‌‌have‌‌an‌‌account‌‌in‌ 
“Newyork”‌‌Branch.‌ 
‌π‌ Customer −Name    (�� Branch−Name=""NEW Y ORK"(  
�� Customer.Cust−id=Account.Cust−id (Customer X Account));    ‌ ‌  
6.Find‌‌the‌‌names‌‌of‌‌all‌‌customers‌‌who‌‌have‌‌a‌‌loan‌‌at‌‌the‌ 
New‌‌York‌‌branch‌‌but‌‌do‌‌not‌‌have‌‌an‌‌account‌‌at‌‌any‌‌branch‌ 
of‌‌the‌‌bank.‌ 
π‌ Customer −Name    (�� Branch−Name=""NEW Y ORK"(  
�� Customer.Cust−id=Account.Cust−id (Customer X Loan))  −‌    
‌π‌ Customer −name    (Account);   ‌
 
 
 
Relational‌‌Algebra:‌ 
‌Notice‌‌the‌‌following‌‌schemas,‌ 
● Student(student_name,student_id,Address,email,phone,‌
Course_name,cgpa,teacher_name);‌ 
● Course(Course_name,Course_id,CreditHour,ContactHo‌
ur);‌ 
● Teacher(teacher_name,teacher_id,joiningDate,yearsOfe‌
xperience,Course_name);‌ 
Now‌‌write‌‌the‌‌following‌‌relational‌‌algebra,‌ 
 
 
1.Show‌‌the‌‌information‌‌of‌‌the‌‌students‌‌living‌‌in‌‌Dhaka.‌ 
‌𝛔 ‌ Student.address="Dhaka"(Student) ;‌  ‌
2.Show‌‌the‌‌name‌‌of‌‌the‌‌teachers‌‌taking‌‌the‌‌course‌ 
“CSE-235”.(Nested‌‌query)‌ 
‌π‌
 ‌  
 T eacher.teacher −name    (�� T eacher.Course−name="CSE−235"(T eacher));
3.Show‌‌the‌‌students'‌‌names‌‌along‌‌with‌‌their‌‌cgpa‌‌&‌‌student‌ 
id.‌ 
‌π‌ Student.student−name,Student.student−id,Student.cgpa    (Student);    ‌ ‌
4.Show‌‌the‌‌name‌‌of‌‌the‌‌teacher‌‌having‌‌experience‌‌over‌‌30‌ 
years.(nested‌‌query);‌ 
π‌ T eacher.teacher −name    (�� T eacher.experience>30 (T eacher));
 ‌  
 
5.Find‌‌out‌‌the‌‌name‌‌of‌‌the‌‌students‌‌who‌‌have‌‌a‌‌course‌‌of‌ 
credit‌‌3.0.‌ 
π‌ Student.Student−name    (Student)     U‌  ‌
π‌ Course.Course−name    (�� Course.creditHour="3.00"(Course));  ‌  
 
 
6.Find‌‌out‌‌the‌‌name‌‌of‌‌the‌‌teacher‌‌who‌‌has‌‌a‌‌student‌ 
residing‌‌in‌‌“Barisal”.‌ 
π‌
 T eacher.teacher −name    (�� Student.teacher −name==T eacher.teacher −name,Student.address=
(‌ Student‌‌X‌‌Teacher)‌ 
 
7.Find‌‌out‌‌the‌‌name‌‌of‌‌the‌‌courses‌‌which‌‌are‌‌being‌‌teached‌ 
by‌‌teacher‌‌“X”.(Home‌‌task)‌ 
8.Find‌‌out‌‌the‌‌the‌‌name‌‌of‌‌the‌‌teacher‌‌who‌‌doesn’t‌‌teach‌‌any‌ 
subject.(Home‌‌task)‌ 
 
 
 
 
CLASS‌‌WORK(4/4/2021(5/4/2021)):‌ 
Branch‌‌(branch_name,‌‌branch_city,‌‌assets)‌ 
Customer‌‌(customer_name,‌‌customer_street,‌ 
customer_city)‌ 
Account‌‌(account_number,‌‌branch_name,‌‌balance)‌ 
Loan‌‌(loan_number,‌‌branch_name,‌‌amount)‌ 
Depositor‌‌(customer_name,‌‌account_number)‌ 
Borrower‌‌(customer_name,‌‌loan_number)‌ 
 
SELECT:‌ 
1.Find‌‌out‌‌the‌‌information‌‌of‌‌the‌‌customer‌‌who‌‌lives‌‌in‌ 
“Dhaka”.‌ 
‌�� Customer.Customer −city="Dhaka"(Customer);
 ‌  
 
PROJECT:‌ 
1.Find‌‌out‌‌the‌‌names‌‌of‌‌the‌‌customers‌‌who‌‌have‌‌loans.‌ 
‌π‌ Borrower.Customer −name    (Borrower) ;‌  ‌
   
‌2.Find‌‌out‌‌the‌‌name‌‌of‌‌the‌‌customer‌‌who‌‌lives‌‌in‌‌“Dhaka”.‌ 
π‌
   
 Customer.Customer −name    (�� Customer.Customer −city="Dhaka"(Customer));
‌3.Find‌‌out‌‌the‌‌account‌‌balance‌‌within‌‌500‌‌taka.‌ 
‌π‌ Account.Balance>=500    (Account);   ‌
   
  
4‌ .Find‌‌out‌‌the‌‌account‌‌information‌ ‌whose‌‌balance‌‌is‌‌not‌ 
more‌‌than‌‌1000‌‌taka.‌ 
‌�� Account.Balance>=1000 (Account);  ‌  
‌5.Find‌‌out‌‌the‌‌account‌‌balance‌‌which‌‌is‌‌not‌‌more‌‌than‌ 
1000‌‌taka.‌ 
‌π‌ Account.Balance>=1000    (Account);   ‌
‌6.Find‌‌out‌‌the‌‌account‌‌number‌‌‌which‌‌balance‌‌is‌‌not‌‌more‌ 
than‌‌1000‌‌taka.‌ 
‌‌π‌ Account.Account−number    (�� Account.Balance>=1000 (Account));
 ‌  
   
 
UNION:‌ 
1.Find‌‌out‌‌the‌‌information‌‌‌of‌‌the‌‌customer‌‌who‌‌has‌‌a‌‌loan‌ 
and‌‌an‌‌account‌‌or‌‌both.‌ 
π‌ depositor.customer −name,depositor.account−number    (depositor)     U‌   ‌ ‌
π‌ borrower.customer −name,borrower.loan−number   (borrower) ;       ‌
 
2.Find‌‌out‌‌the‌‌name‌‌of‌‌the‌‌customer‌‌who‌‌has‌‌a‌‌loan‌‌and‌‌an‌ 
account‌‌or‌‌both.‌ 
π‌ depositor.customer −name    (depositor)     U‌   ‌ ‌
π‌ borrower.customer −name    (borrower) ;       ‌
3.Find‌‌out‌‌the‌‌branch‌‌names‌‌where‌‌the‌‌customer‌‌has‌‌a‌‌loan‌ 
and‌‌an‌‌account‌‌both.‌ 
π‌ Account.branch−name    (Account)     U‌   ‌ ‌
π‌ Loan.branch−name    (Loan) ;       ‌
 
Cartesian‌‌Product:‌ 
1.Find‌‌the‌‌names‌‌of‌‌all‌‌customers‌‌who‌‌have‌‌a‌‌loan‌ 
at‌‌the‌‌Dhaka‌‌branch.‌ 
π‌
 borrower.Customer−name    ((�� loan.branch="Dhak a" (�� loan.loan−number==borrower.loan−number (loan X  bor
  
2.Find‌‌out‌‌the‌‌customer‌‌name‌‌who‌‌has‌‌both‌‌a‌‌loan‌‌and‌‌an‌ 
account‌‌on‌‌“DHAKA”‌‌branch.‌ 
‌[‌ ‌1‌‌U‌‌2‌ ‌]‌ 
‌3)Find‌‌out‌‌the‌‌name‌‌of‌‌the‌‌customer‌‌who‌‌has‌‌an‌‌account‌ 
on‌‌the‌‌“Dhaka”‌‌branch.‌ 
𝜫‌ Depositor.Customer−name ( 𝞼‌  ‌
 
 ‌
 Account.Branch−name="Dhak a" (�� Account.Account−number==Depositor.Account−number (Depositor X  Account))
   
Set‌‌Difference:‌ 
1.‌Find‌‌out‌‌the‌‌branch‌‌names‌‌where‌‌the‌‌customer‌‌only‌‌has‌‌a‌ 
loan‌‌‌not‌‌an‌‌account.‌ 
A={1,‌2,3,‌4},‌‌B={‌2,3‌,6,7,8}‌ 
A‌‌-‌‌B‌‌=‌‌{1,4}‌ 
B‌‌-‌‌A‌‌=‌‌{6,7,8}‌ 
‌π‌ Loan.Branch−name    (Loan);   ‌

π‌
 Loan.Branch−name    (π Loan.Branch−name==Branch.Branch−name    (Loan X Branch)) −  
‌π‌ Account.Branch−name    (Account);   ‌
‌OR‌ 
‌π‌ Loan.Branch−name    (Loan) ‌- ‌ ‌
‌π‌ Account.Branch−name    (Account);    ‌ ‌
Loan‌‌→‌‌Khilgaon,‌Dhanmondi,Gulshan‌ 
Branch→Khilgaon,Gulshan,Badda,Banani,Mohakhali‌ 
Account‌‌→‌ ‌Badda,Wari,Banani,Khilgaon‌ 
2‌.Find‌‌the‌‌names‌‌of‌‌all‌‌customers‌‌who‌‌have‌‌a‌‌loan‌‌at‌‌the‌ 
Gulshan‌‌branch‌‌but‌‌do‌‌not‌‌have‌‌an‌‌account‌‌at‌‌any‌‌branch‌‌of‌ 
the‌‌bank‌.‌ 
‌π‌ Borrower.Customer −name    (�� Loan.Branch−name="Gulshan"   
 ‌  
‌(‌(�� Loan.loan−number==Borrower.loan−number    (Borrower X Loan)
)‌  ‌  
- π‌ Depositor.Customer−name   (Depositor);   ‌
 
Rename:(MIN,MAX,AVG,SUM,COUNT)‌ 
‌1.Find‌‌the‌‌largest‌‌account‌‌balance.‌ 
   
‌π‌ Account.Balance    (  ‌
(�� Account.Balance < new.Balance    (Account X ρ new (Account))  
));{MAX}‌ 
‌π‌ Account.Balance    (  ‌
(�� Account.Balance > new.Balance    (Account X ρ new (Account))  
));[MIN]‌ 
‌π‌ Account.Balance    ( ‌‌(�� Account.Balance = new.Balance+new2.Balance     ((‌  
Account X ρ new (Account) X ρ new2 Account)  ));[SUM]‌  ‌
 
 
 
 
 
 
 

You might also like