SlideShare a Scribd company logo
7/11/2016 Prepared By- Shimul & Hirok,CSE,MBSTU 1
WELCOME
TO OUR
PRESENTATION
SQL and E-R diagram related
problems and its solution.
7/11/2016 2Prepared By- Shimul & Hirok,CSE,MBSTU
Presentation on……
Presented By
• NAME : ID:
• MD.MAHBUBUR RAHMAN CE-12038
• HIROK BISWAS CE-12032
We are going to talking about
 SQL expressions:
 sample bank database(3.19)
 relational schema(3.21,3.22)
E-R diagram for a hospital(6.15)
UML equivalents of the E-R diagrams(6.28)
Conclution
7/11/2016 Prepared By- Shimul & Hirok,CSE,MBSTU 3
Problem 1 :
Using the relations of our sample bank database, write SQL expressions to
define the following views:
a. A view containing the account numbers and customer names (but not the
balances) for all accounts at the Deer Park branch.
b. A view containing the names and addresses of all customers who have an
account with the bank, but do not have a loan.
c. A view containing the name and average account balance of every customer
of the Rock Ridge branch.
Solution of Problem 1 (a)
A view containing the account numbers and customer names (but not
the balances) for all accounts at the Deer Park branch.
Table: accountTable: depositor
7/11/2016 5Prepared By- Shimul & Hirok,CSE,MBSTU
Solution of Problem 1 (a)( Cont…)
• Query:
select depositor.customer_name,depositor.account_number
from depositor,account
where depositor.account_number =account.account_number
and account.branch_name='Deer Park';
• Table view:
7/11/2016 6Prepared By- Shimul & Hirok,CSE,MBSTU
Solution of Problem 1 (b)
A view containing the names and addresses of all customers who have
an account with the bank, but do not have a borrower.
Table: customer Table: depositor Table: borrower
7/11/2016 7Prepared By- Shimul & Hirok,CSE,MBSTU
Solution of Problem 1 (b)(Cont…)
select c.customer_name, c.customer_street,
c.customer_city
from customer c, depositor d
where c.customer_name not in (select
customer_name
from borrower)
and c.customer_name = d.customer_name;
• Query:
• Table view:
7/11/2016 8Prepared By- Shimul & Hirok,CSE,MBSTU
Solution of Problem 1 (c)
. A view containing the name and average account balance of every
customer of the 'sidney' branch.
Table: account Table: depositor
7/11/2016 9Prepared By- Shimul & Hirok,CSE,MBSTU
Solution of Problem 1 (c) (Cont…)
select customer_name, avg(a.balance)
from account a, depositor d
where a.account_number = d.account_number
and branch_name='sidney'
group by customer_name;
• Query:
• Table view:
7/11/2016 10Prepared By- Shimul & Hirok,CSE,MBSTU
Problem 1 (EXP-02) :
create procedure get_emp(employee_id in varchar(10))
return char
BEGIN
select employee.employee_id,department.department_name,salary.salary_scale,salary.salary_amount from department
inner join employee_department on department.department_id=employee_department.department_id
inner join employee on employee.employee_id=employee_department.employee_id
inner join employee_salary on employee.employee_id=employee_salary.employee_id
inner join salary on salary.salary_scale=employee_salary.salary_scale
where employee.employee_id=employee_id;
return(employee_id);
END;
Exec get_emp('emp02');
Solution of Problem 1 (Exp-2):
Create a procedure that will take Employee_ID it’s parameter return
Employee_ID ,Department_Name, Salary_Scale and Salary_Amount.
7/11/2016 11Prepared By- Shimul & Hirok,CSE,MBSTU
Problem 2 :
Consider the following relational schema
employee(emp_no , name, office, age)
books(isbn , title, authors, publisher)
loan(emp_no , isbn, date)
Write the following queries in SQL.
a. Print the names of employees who have borrowed any book published by
McGraw-Hill.
b. Print the names of employees who have borrowed all books published by
McGraw-Hill.
c. For each publisher, print the names of employees who have borrowed more than five
books of that publisher.
7/11/2016 12Prepared By- Shimul & Hirok,CSE,MBSTU
Solution of Problem 2 (a)
Print the names of employees who have borrowed any book published
by McGraw-Hill.
Table: employee
Table: books
Table: loan
7/11/2016 13Prepared By- Shimul & Hirok,CSE,MBSTU
Solution of Problem 2 (a) (cont…)
• Query:
select distinct name as employee_name from employee
inner join loan on employee.emp_no=loan.emp_no
inner join books on loan.isbn=books.isbn
where books.publisher='Mcgraw-hill';
• Table view:
7/11/2016 14Prepared By- Shimul & Hirok,CSE,MBSTU
Solution of Problem 2 (b)
Print the names of employees who have borrowed all book published
by McGraw-Hill.
Table: employee
Table: books
Table: loan
result
7/11/2016 15Prepared By- Shimul & Hirok,CSE,MBSTU
Solution of Problem 2 (b) (cont…)
• Query:
select distinct name as employee_name from employee
inner join loan on employee.emp_no=loan.emp_no
inner join books on loan.isbn=books.isbn
where (select count(loan.isbn) from loan where
loan.emp_no=employee.emp_no)=(select count(books.isbn) from books
where books.publisher='Mcgraw-hill');
• Table view:
7/11/2016 16Prepared By- Shimul & Hirok,CSE,MBSTU
Solution of Problem 2 (c)
For each publisher, print the names of employees who have borrowed
more than five books of that publisher.
Table: employee
Table: books
Table: loan
result
More than
5
Books from
Mcgraw-hill
(only)
7/11/2016 17Prepared By- Shimul & Hirok,CSE,MBSTU
Solution of Problem 2 (c) (cont…)
• Query:
select name from employee,loan,books
where employee.emp_no=loan.emp_no and
books.isbn=loan.isbn
group by employee.emp_no,name,books.publisher having
count(loan.isbn) >=5;
• Table view:
7/11/2016 18Prepared By- Shimul & Hirok,CSE,MBSTU
Problem 3 :
Consider the relational schema
student(student_id , student_name)
registerd(student_id , course_id)
Write an SQL query to list the student-id and name of each
student along with the total number of courses that the student is
registered for. Students who are not registerd for any course must
also be listed, with the number of registerd
courses shown as 0.
7/11/2016 19Prepared By- Shimul & Hirok,CSE,MBSTU
Solution of Problem 3
Table: student
Table: registerd
a is registerd by
3
course
b is registerd by
1
course
C is not
registerd
(0)
7/11/2016 20Prepared By- Shimul & Hirok,CSE,MBSTU
Solution of Problem 3 (cont…)
• Query:
select student_id,student_name,(select count(registerd.course_id) from registerd
where student.student_id=registerd.student_id) as taken_course
from student;
• Table view:
7/11/2016 21Prepared By- Shimul & Hirok,CSE,MBSTU
Problem 4:
Consider the relational schema:
Department (Department _ID , Department _Name)
Employee (Employee_ID , Employee_Name,Employee_Age)
Employee _Department( Employee _ID , Department _ID )
Salary (Salary _Scale , Salary _Amount)
Employee_ Salary (Employee _ID , Salary _Scale)
a) Find the Department_names where the employee’s average salary is more
than 10000.
b) Find the employee_names who has paid in salary scale 1.
c) Update the employee ages by increasing 10 years whose ages are not equal
to average age.
7/11/2016 22Prepared By- Shimul & Hirok,CSE,MBSTU
Solution of Problem 4 (a)
Find the Department_names where the employee’s average salary is more
than 10000.
Table: department Table: employee_department
Table: employee_salary
Table: salary
7/11/2016 23Prepared By- Shimul & Hirok,CSE,MBSTU
Solution of Problem 4(a) (cont…)
• Query:
select department_name,avg(salary.salary_amount) from department
inner join employee_department on
department.department_id=employee_department.department_id
inner join employee_salary on
employee_department.employee_id=employee_salary.employee_id
inner join salary on salary.salary_scale=employee_salary.salary_scale
having avg(salary.salary_amount)>10000
group by department.department_name;
• Table view:
7/11/2016 24Prepared By- Shimul & Hirok,CSE,MBSTU
Solution of Problem 4 (b)
Find the employee_names who has paid in salary scale 1.
Table: Employee Table: employee_salary
Table: salary
result
7/11/2016 25Prepared By- Shimul & Hirok,CSE,MBSTU
Solution of Problem 4(b) (cont…)
• Query:
select employee_name from employee inner join employee_salary
on employee_salary.employee_id=employee.employee_id
inner join salary on salary.salary_scale=employee_salary.salary_scale
where salary.salary_scale=1;
• Table view:
7/11/2016 26Prepared By- Shimul & Hirok,CSE,MBSTU
Solution of Problem 4(c)
• Query:
update employee
set employee.employee_age=employee.employee_age+1
where employee.employee_age not in (select avg(employee.employee_age) from employee);
• Table view:
Before update:
After update:
Average
age
7/11/2016 27Prepared By- Shimul & Hirok,CSE,MBSTU
Problem 5
Construct an E-R diagram for a hospital with a
set of patients and a set of medical doctors.
Associate with each patient a log of the
various tests and examinations conducted.
7/11/2016 28Prepared By- Shimul & Hirok,CSE,MBSTU
Solution Of problem 5:
Fig: E-R diagram for a hospital system.
7/11/2016 29Prepared By- Shimul & Hirok,CSE,MBSTU
Problem 6
Draw the UML equivalents of the
E-R diagrams Of Figures
6.8c,6.9,6.17,6.72,And 6.20.
7/11/2016 30Prepared By- Shimul & Hirok,CSE,MBSTU
Needed Figure of Problem 6 And Its
Solution Given…………………….
7/11/2016 31Prepared By- Shimul & Hirok,CSE,MBSTU
Fig:6.8c Relationship(One –to-one)
Solution of Fig 6.8c:
7/11/2016 32Prepared By- Shimul & Hirok,CSE,MBSTU
Solution of Fig 6.9:
7/11/2016 33Prepared By- Shimul & Hirok,CSE,MBSTU
Solution of Fig 6.11:
7/11/2016 34Prepared By- Shimul & Hirok,CSE,MBSTU
Solution of Fig 6.12:
7/11/2016 35Prepared By- Shimul & Hirok,CSE,MBSTU
7/11/2016 36Prepared By- Shimul & Hirok,CSE,MBSTU
Solution of Fig 6.20(Cont….)
7/11/2016 37Prepared By- Shimul & Hirok,CSE,MBSTU
THANK
YOU
7/11/2016 Prepared By- Shimul & Hirok,CSE,MBSTU 38

More Related Content

What's hot

Bayesian networks in AI
Bayesian networks in AIBayesian networks in AI
Bayesian networks in AI
Byoung-Hee Kim
 
ER Modeling and Introduction to RDBMS
ER Modeling and Introduction to RDBMSER Modeling and Introduction to RDBMS
ER Modeling and Introduction to RDBMS
Rubal Sagwal
 
Fundamentals of data structures ellis horowitz & sartaj sahni
Fundamentals of data structures   ellis horowitz & sartaj sahniFundamentals of data structures   ellis horowitz & sartaj sahni
Fundamentals of data structures ellis horowitz & sartaj sahniHitesh Wagle
 
heap Sort Algorithm
heap  Sort Algorithmheap  Sort Algorithm
heap Sort Algorithm
Lemia Algmri
 
Algorithm analysis
Algorithm analysisAlgorithm analysis
Algorithm analysissumitbardhan
 
Design and Analysis of Algorithms
Design and Analysis of AlgorithmsDesign and Analysis of Algorithms
Design and Analysis of Algorithms
Swapnil Agrawal
 
Project of data structure
Project of data structureProject of data structure
Project of data structure
Umme habiba
 
Inter process communication
Inter process communicationInter process communication
Inter process communicationMohd Tousif
 
Frequent itemset mining methods
Frequent itemset mining methodsFrequent itemset mining methods
Frequent itemset mining methods
Prof.Nilesh Magar
 
LALR Parser Presentation ppt
LALR Parser Presentation pptLALR Parser Presentation ppt
LALR Parser Presentation ppt
WPVKP.COM
 
Greedy Algorithm - Knapsack Problem
Greedy Algorithm - Knapsack ProblemGreedy Algorithm - Knapsack Problem
Greedy Algorithm - Knapsack Problem
Madhu Bala
 
Predicate logic
 Predicate logic Predicate logic
Predicate logic
Harini Balamurugan
 
Stack & Queue using Linked List in Data Structure
Stack & Queue using Linked List in Data StructureStack & Queue using Linked List in Data Structure
Stack & Queue using Linked List in Data Structure
Meghaj Mallick
 
Planning
PlanningPlanning
Planning
ahmad bassiouny
 
BackTracking Algorithm: Technique and Examples
BackTracking Algorithm: Technique and ExamplesBackTracking Algorithm: Technique and Examples
BackTracking Algorithm: Technique and Examples
Fahim Ferdous
 
I. AO* SEARCH ALGORITHM
I. AO* SEARCH ALGORITHMI. AO* SEARCH ALGORITHM
I. AO* SEARCH ALGORITHM
vikas dhakane
 
sum of subset problem using Backtracking
sum of subset problem using Backtrackingsum of subset problem using Backtracking
sum of subset problem using Backtracking
Abhishek Singh
 
Domain model Refinement
Domain model RefinementDomain model Refinement
Domain model Refinement
Anjan Kumar
 
illumination model in Computer Graphics by irru pychukar
illumination model in Computer Graphics by irru pychukarillumination model in Computer Graphics by irru pychukar
illumination model in Computer Graphics by irru pychukar
syedArr
 
Turing Machine
Turing MachineTuring Machine
Turing Machine
Rajendran
 

What's hot (20)

Bayesian networks in AI
Bayesian networks in AIBayesian networks in AI
Bayesian networks in AI
 
ER Modeling and Introduction to RDBMS
ER Modeling and Introduction to RDBMSER Modeling and Introduction to RDBMS
ER Modeling and Introduction to RDBMS
 
Fundamentals of data structures ellis horowitz & sartaj sahni
Fundamentals of data structures   ellis horowitz & sartaj sahniFundamentals of data structures   ellis horowitz & sartaj sahni
Fundamentals of data structures ellis horowitz & sartaj sahni
 
heap Sort Algorithm
heap  Sort Algorithmheap  Sort Algorithm
heap Sort Algorithm
 
Algorithm analysis
Algorithm analysisAlgorithm analysis
Algorithm analysis
 
Design and Analysis of Algorithms
Design and Analysis of AlgorithmsDesign and Analysis of Algorithms
Design and Analysis of Algorithms
 
Project of data structure
Project of data structureProject of data structure
Project of data structure
 
Inter process communication
Inter process communicationInter process communication
Inter process communication
 
Frequent itemset mining methods
Frequent itemset mining methodsFrequent itemset mining methods
Frequent itemset mining methods
 
LALR Parser Presentation ppt
LALR Parser Presentation pptLALR Parser Presentation ppt
LALR Parser Presentation ppt
 
Greedy Algorithm - Knapsack Problem
Greedy Algorithm - Knapsack ProblemGreedy Algorithm - Knapsack Problem
Greedy Algorithm - Knapsack Problem
 
Predicate logic
 Predicate logic Predicate logic
Predicate logic
 
Stack & Queue using Linked List in Data Structure
Stack & Queue using Linked List in Data StructureStack & Queue using Linked List in Data Structure
Stack & Queue using Linked List in Data Structure
 
Planning
PlanningPlanning
Planning
 
BackTracking Algorithm: Technique and Examples
BackTracking Algorithm: Technique and ExamplesBackTracking Algorithm: Technique and Examples
BackTracking Algorithm: Technique and Examples
 
I. AO* SEARCH ALGORITHM
I. AO* SEARCH ALGORITHMI. AO* SEARCH ALGORITHM
I. AO* SEARCH ALGORITHM
 
sum of subset problem using Backtracking
sum of subset problem using Backtrackingsum of subset problem using Backtracking
sum of subset problem using Backtracking
 
Domain model Refinement
Domain model RefinementDomain model Refinement
Domain model Refinement
 
illumination model in Computer Graphics by irru pychukar
illumination model in Computer Graphics by irru pychukarillumination model in Computer Graphics by irru pychukar
illumination model in Computer Graphics by irru pychukar
 
Turing Machine
Turing MachineTuring Machine
Turing Machine
 

Similar to SQL and E R diagram

Simran kaur,BCA Final Year 2015
Simran kaur,BCA Final Year 2015Simran kaur,BCA Final Year 2015
Simran kaur,BCA Final Year 2015
dezyneecole
 
Divyansh Mehta,BCA Final Year 2015 ,Dezyne E'cole College
Divyansh Mehta,BCA Final Year 2015 ,Dezyne E'cole CollegeDivyansh Mehta,BCA Final Year 2015 ,Dezyne E'cole College
Divyansh Mehta,BCA Final Year 2015 ,Dezyne E'cole College
dezyneecole
 
Nikhil Khandelwal BCA 3rd Year
Nikhil Khandelwal BCA 3rd YearNikhil Khandelwal BCA 3rd Year
Nikhil Khandelwal BCA 3rd Year
dezyneecole
 
Priyanka Bhatia.BCA Final year 2015
Priyanka Bhatia.BCA Final year 2015Priyanka Bhatia.BCA Final year 2015
Priyanka Bhatia.BCA Final year 2015
dezyneecole
 
Vijay Kumar
Vijay KumarVijay Kumar
Vijay Kumar
dezyneecole
 
Pooja Bijawat,Bachelor Degree in Computer Application
Pooja Bijawat,Bachelor Degree in Computer ApplicationPooja Bijawat,Bachelor Degree in Computer Application
Pooja Bijawat,Bachelor Degree in Computer Application
dezyneecole
 
Vishwajeet Sikhwal ,BCA,Final Year 2015
Vishwajeet Sikhwal ,BCA,Final Year 2015Vishwajeet Sikhwal ,BCA,Final Year 2015
Vishwajeet Sikhwal ,BCA,Final Year 2015
dezyneecole
 
Pseudocode algorithim flowchart
Pseudocode algorithim flowchartPseudocode algorithim flowchart
Pseudocode algorithim flowchart
fika sweety
 
Review the SHRM case Designing a Pay Structure” You will p.docx
Review the SHRM case Designing a Pay Structure” You will p.docxReview the SHRM case Designing a Pay Structure” You will p.docx
Review the SHRM case Designing a Pay Structure” You will p.docx
fathwaitewalter
 
Database Assignment
Database AssignmentDatabase Assignment
Database Assignment
Jayed Imran
 
Apurv Gupta, BCA ,Final year , Dezyne E'cole College
 Apurv Gupta, BCA ,Final year , Dezyne E'cole College Apurv Gupta, BCA ,Final year , Dezyne E'cole College
Apurv Gupta, BCA ,Final year , Dezyne E'cole College
dezyneecole
 
Chapter 1 TestSuppose that you are an administrator in a .docx
Chapter 1 TestSuppose that you are an administrator in a .docxChapter 1 TestSuppose that you are an administrator in a .docx
Chapter 1 TestSuppose that you are an administrator in a .docx
sleeperharwell
 
James Colby Maddox Business Intellignece and Computer Science Portfolio
James Colby Maddox Business Intellignece and Computer Science PortfolioJames Colby Maddox Business Intellignece and Computer Science Portfolio
James Colby Maddox Business Intellignece and Computer Science Portfolio
colbydaman
 
Da 100-questions
Da 100-questionsDa 100-questions
Da 100-questions
Sandeep Kumar Chavan
 
Ace the C_THR92_2305 Certification Exam - Expert Preparation Guide
Ace the C_THR92_2305 Certification Exam - Expert Preparation GuideAce the C_THR92_2305 Certification Exam - Expert Preparation Guide
Ace the C_THR92_2305 Certification Exam - Expert Preparation Guide
Aliza Oscar
 
C_THR87_2305 Certification Exam Validate Your HR Expertise
C_THR87_2305 Certification Exam Validate Your HR ExpertiseC_THR87_2305 Certification Exam Validate Your HR Expertise
C_THR87_2305 Certification Exam Validate Your HR Expertise
Aliza Oscar
 
Introduction to database-Formal Query language and Relational calculus
Introduction to database-Formal Query language and Relational calculusIntroduction to database-Formal Query language and Relational calculus
Introduction to database-Formal Query language and Relational calculus
Ajit Nayak
 
Complete practical file of class xii cs 2021-22
Complete practical file of class xii cs 2021-22Complete practical file of class xii cs 2021-22
Complete practical file of class xii cs 2021-22
manyaarora19
 

Similar to SQL and E R diagram (20)

Simran kaur,BCA Final Year 2015
Simran kaur,BCA Final Year 2015Simran kaur,BCA Final Year 2015
Simran kaur,BCA Final Year 2015
 
Divyansh Mehta,BCA Final Year 2015 ,Dezyne E'cole College
Divyansh Mehta,BCA Final Year 2015 ,Dezyne E'cole CollegeDivyansh Mehta,BCA Final Year 2015 ,Dezyne E'cole College
Divyansh Mehta,BCA Final Year 2015 ,Dezyne E'cole College
 
Nikhil Khandelwal BCA 3rd Year
Nikhil Khandelwal BCA 3rd YearNikhil Khandelwal BCA 3rd Year
Nikhil Khandelwal BCA 3rd Year
 
Priyanka Bhatia.BCA Final year 2015
Priyanka Bhatia.BCA Final year 2015Priyanka Bhatia.BCA Final year 2015
Priyanka Bhatia.BCA Final year 2015
 
Vijay Kumar
Vijay KumarVijay Kumar
Vijay Kumar
 
Pooja Bijawat,Bachelor Degree in Computer Application
Pooja Bijawat,Bachelor Degree in Computer ApplicationPooja Bijawat,Bachelor Degree in Computer Application
Pooja Bijawat,Bachelor Degree in Computer Application
 
Vishwajeet Sikhwal ,BCA,Final Year 2015
Vishwajeet Sikhwal ,BCA,Final Year 2015Vishwajeet Sikhwal ,BCA,Final Year 2015
Vishwajeet Sikhwal ,BCA,Final Year 2015
 
Pseudocode algorithim flowchart
Pseudocode algorithim flowchartPseudocode algorithim flowchart
Pseudocode algorithim flowchart
 
Review the SHRM case Designing a Pay Structure” You will p.docx
Review the SHRM case Designing a Pay Structure” You will p.docxReview the SHRM case Designing a Pay Structure” You will p.docx
Review the SHRM case Designing a Pay Structure” You will p.docx
 
Database Assignment
Database AssignmentDatabase Assignment
Database Assignment
 
Apurv Gupta, BCA ,Final year , Dezyne E'cole College
 Apurv Gupta, BCA ,Final year , Dezyne E'cole College Apurv Gupta, BCA ,Final year , Dezyne E'cole College
Apurv Gupta, BCA ,Final year , Dezyne E'cole College
 
Chapter 1 TestSuppose that you are an administrator in a .docx
Chapter 1 TestSuppose that you are an administrator in a .docxChapter 1 TestSuppose that you are an administrator in a .docx
Chapter 1 TestSuppose that you are an administrator in a .docx
 
James Colby Maddox Business Intellignece and Computer Science Portfolio
James Colby Maddox Business Intellignece and Computer Science PortfolioJames Colby Maddox Business Intellignece and Computer Science Portfolio
James Colby Maddox Business Intellignece and Computer Science Portfolio
 
Da 100-questions
Da 100-questionsDa 100-questions
Da 100-questions
 
Ace the C_THR92_2305 Certification Exam - Expert Preparation Guide
Ace the C_THR92_2305 Certification Exam - Expert Preparation GuideAce the C_THR92_2305 Certification Exam - Expert Preparation Guide
Ace the C_THR92_2305 Certification Exam - Expert Preparation Guide
 
C_THR87_2305 Certification Exam Validate Your HR Expertise
C_THR87_2305 Certification Exam Validate Your HR ExpertiseC_THR87_2305 Certification Exam Validate Your HR Expertise
C_THR87_2305 Certification Exam Validate Your HR Expertise
 
Db
DbDb
Db
 
B-Project Report-SSAS
B-Project Report-SSASB-Project Report-SSAS
B-Project Report-SSAS
 
Introduction to database-Formal Query language and Relational calculus
Introduction to database-Formal Query language and Relational calculusIntroduction to database-Formal Query language and Relational calculus
Introduction to database-Formal Query language and Relational calculus
 
Complete practical file of class xii cs 2021-22
Complete practical file of class xii cs 2021-22Complete practical file of class xii cs 2021-22
Complete practical file of class xii cs 2021-22
 

Recently uploaded

Technical Drawings introduction to drawing of prisms
Technical Drawings introduction to drawing of prismsTechnical Drawings introduction to drawing of prisms
Technical Drawings introduction to drawing of prisms
heavyhaig
 
6th International Conference on Machine Learning & Applications (CMLA 2024)
6th International Conference on Machine Learning & Applications (CMLA 2024)6th International Conference on Machine Learning & Applications (CMLA 2024)
6th International Conference on Machine Learning & Applications (CMLA 2024)
ClaraZara1
 
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
thanhdowork
 
weather web application report.pdf
weather web application report.pdfweather web application report.pdf
weather web application report.pdf
Pratik Pawar
 
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&BDesign and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Sreedhar Chowdam
 
Final project report on grocery store management system..pdf
Final project report on grocery store management system..pdfFinal project report on grocery store management system..pdf
Final project report on grocery store management system..pdf
Kamal Acharya
 
14 Template Contractual Notice - EOT Application
14 Template Contractual Notice - EOT Application14 Template Contractual Notice - EOT Application
14 Template Contractual Notice - EOT Application
SyedAbiiAzazi1
 
Building Electrical System Design & Installation
Building Electrical System Design & InstallationBuilding Electrical System Design & Installation
Building Electrical System Design & Installation
symbo111
 
Basic Industrial Engineering terms for apparel
Basic Industrial Engineering terms for apparelBasic Industrial Engineering terms for apparel
Basic Industrial Engineering terms for apparel
top1002
 
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
Amil Baba Dawood bangali
 
Forklift Classes Overview by Intella Parts
Forklift Classes Overview by Intella PartsForklift Classes Overview by Intella Parts
Forklift Classes Overview by Intella Parts
Intella Parts
 
Fundamentals of Electric Drives and its applications.pptx
Fundamentals of Electric Drives and its applications.pptxFundamentals of Electric Drives and its applications.pptx
Fundamentals of Electric Drives and its applications.pptx
manasideore6
 
MCQ Soil mechanics questions (Soil shear strength).pdf
MCQ Soil mechanics questions (Soil shear strength).pdfMCQ Soil mechanics questions (Soil shear strength).pdf
MCQ Soil mechanics questions (Soil shear strength).pdf
Osamah Alsalih
 
Cosmetic shop management system project report.pdf
Cosmetic shop management system project report.pdfCosmetic shop management system project report.pdf
Cosmetic shop management system project report.pdf
Kamal Acharya
 
DESIGN AND ANALYSIS OF A CAR SHOWROOM USING E TABS
DESIGN AND ANALYSIS OF A CAR SHOWROOM USING E TABSDESIGN AND ANALYSIS OF A CAR SHOWROOM USING E TABS
DESIGN AND ANALYSIS OF A CAR SHOWROOM USING E TABS
itech2017
 
Hierarchical Digital Twin of a Naval Power System
Hierarchical Digital Twin of a Naval Power SystemHierarchical Digital Twin of a Naval Power System
Hierarchical Digital Twin of a Naval Power System
Kerry Sado
 
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理
zwunae
 
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdfTop 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Teleport Manpower Consultant
 
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Dr.Costas Sachpazis
 
Recycled Concrete Aggregate in Construction Part III
Recycled Concrete Aggregate in Construction Part IIIRecycled Concrete Aggregate in Construction Part III
Recycled Concrete Aggregate in Construction Part III
Aditya Rajan Patra
 

Recently uploaded (20)

Technical Drawings introduction to drawing of prisms
Technical Drawings introduction to drawing of prismsTechnical Drawings introduction to drawing of prisms
Technical Drawings introduction to drawing of prisms
 
6th International Conference on Machine Learning & Applications (CMLA 2024)
6th International Conference on Machine Learning & Applications (CMLA 2024)6th International Conference on Machine Learning & Applications (CMLA 2024)
6th International Conference on Machine Learning & Applications (CMLA 2024)
 
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
 
weather web application report.pdf
weather web application report.pdfweather web application report.pdf
weather web application report.pdf
 
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&BDesign and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
 
Final project report on grocery store management system..pdf
Final project report on grocery store management system..pdfFinal project report on grocery store management system..pdf
Final project report on grocery store management system..pdf
 
14 Template Contractual Notice - EOT Application
14 Template Contractual Notice - EOT Application14 Template Contractual Notice - EOT Application
14 Template Contractual Notice - EOT Application
 
Building Electrical System Design & Installation
Building Electrical System Design & InstallationBuilding Electrical System Design & Installation
Building Electrical System Design & Installation
 
Basic Industrial Engineering terms for apparel
Basic Industrial Engineering terms for apparelBasic Industrial Engineering terms for apparel
Basic Industrial Engineering terms for apparel
 
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
 
Forklift Classes Overview by Intella Parts
Forklift Classes Overview by Intella PartsForklift Classes Overview by Intella Parts
Forklift Classes Overview by Intella Parts
 
Fundamentals of Electric Drives and its applications.pptx
Fundamentals of Electric Drives and its applications.pptxFundamentals of Electric Drives and its applications.pptx
Fundamentals of Electric Drives and its applications.pptx
 
MCQ Soil mechanics questions (Soil shear strength).pdf
MCQ Soil mechanics questions (Soil shear strength).pdfMCQ Soil mechanics questions (Soil shear strength).pdf
MCQ Soil mechanics questions (Soil shear strength).pdf
 
Cosmetic shop management system project report.pdf
Cosmetic shop management system project report.pdfCosmetic shop management system project report.pdf
Cosmetic shop management system project report.pdf
 
DESIGN AND ANALYSIS OF A CAR SHOWROOM USING E TABS
DESIGN AND ANALYSIS OF A CAR SHOWROOM USING E TABSDESIGN AND ANALYSIS OF A CAR SHOWROOM USING E TABS
DESIGN AND ANALYSIS OF A CAR SHOWROOM USING E TABS
 
Hierarchical Digital Twin of a Naval Power System
Hierarchical Digital Twin of a Naval Power SystemHierarchical Digital Twin of a Naval Power System
Hierarchical Digital Twin of a Naval Power System
 
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理
 
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdfTop 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
 
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
 
Recycled Concrete Aggregate in Construction Part III
Recycled Concrete Aggregate in Construction Part IIIRecycled Concrete Aggregate in Construction Part III
Recycled Concrete Aggregate in Construction Part III
 

SQL and E R diagram

  • 1. 7/11/2016 Prepared By- Shimul & Hirok,CSE,MBSTU 1 WELCOME TO OUR PRESENTATION
  • 2. SQL and E-R diagram related problems and its solution. 7/11/2016 2Prepared By- Shimul & Hirok,CSE,MBSTU Presentation on…… Presented By • NAME : ID: • MD.MAHBUBUR RAHMAN CE-12038 • HIROK BISWAS CE-12032
  • 3. We are going to talking about  SQL expressions:  sample bank database(3.19)  relational schema(3.21,3.22) E-R diagram for a hospital(6.15) UML equivalents of the E-R diagrams(6.28) Conclution 7/11/2016 Prepared By- Shimul & Hirok,CSE,MBSTU 3
  • 4. Problem 1 : Using the relations of our sample bank database, write SQL expressions to define the following views: a. A view containing the account numbers and customer names (but not the balances) for all accounts at the Deer Park branch. b. A view containing the names and addresses of all customers who have an account with the bank, but do not have a loan. c. A view containing the name and average account balance of every customer of the Rock Ridge branch.
  • 5. Solution of Problem 1 (a) A view containing the account numbers and customer names (but not the balances) for all accounts at the Deer Park branch. Table: accountTable: depositor 7/11/2016 5Prepared By- Shimul & Hirok,CSE,MBSTU
  • 6. Solution of Problem 1 (a)( Cont…) • Query: select depositor.customer_name,depositor.account_number from depositor,account where depositor.account_number =account.account_number and account.branch_name='Deer Park'; • Table view: 7/11/2016 6Prepared By- Shimul & Hirok,CSE,MBSTU
  • 7. Solution of Problem 1 (b) A view containing the names and addresses of all customers who have an account with the bank, but do not have a borrower. Table: customer Table: depositor Table: borrower 7/11/2016 7Prepared By- Shimul & Hirok,CSE,MBSTU
  • 8. Solution of Problem 1 (b)(Cont…) select c.customer_name, c.customer_street, c.customer_city from customer c, depositor d where c.customer_name not in (select customer_name from borrower) and c.customer_name = d.customer_name; • Query: • Table view: 7/11/2016 8Prepared By- Shimul & Hirok,CSE,MBSTU
  • 9. Solution of Problem 1 (c) . A view containing the name and average account balance of every customer of the 'sidney' branch. Table: account Table: depositor 7/11/2016 9Prepared By- Shimul & Hirok,CSE,MBSTU
  • 10. Solution of Problem 1 (c) (Cont…) select customer_name, avg(a.balance) from account a, depositor d where a.account_number = d.account_number and branch_name='sidney' group by customer_name; • Query: • Table view: 7/11/2016 10Prepared By- Shimul & Hirok,CSE,MBSTU
  • 11. Problem 1 (EXP-02) : create procedure get_emp(employee_id in varchar(10)) return char BEGIN select employee.employee_id,department.department_name,salary.salary_scale,salary.salary_amount from department inner join employee_department on department.department_id=employee_department.department_id inner join employee on employee.employee_id=employee_department.employee_id inner join employee_salary on employee.employee_id=employee_salary.employee_id inner join salary on salary.salary_scale=employee_salary.salary_scale where employee.employee_id=employee_id; return(employee_id); END; Exec get_emp('emp02'); Solution of Problem 1 (Exp-2): Create a procedure that will take Employee_ID it’s parameter return Employee_ID ,Department_Name, Salary_Scale and Salary_Amount. 7/11/2016 11Prepared By- Shimul & Hirok,CSE,MBSTU
  • 12. Problem 2 : Consider the following relational schema employee(emp_no , name, office, age) books(isbn , title, authors, publisher) loan(emp_no , isbn, date) Write the following queries in SQL. a. Print the names of employees who have borrowed any book published by McGraw-Hill. b. Print the names of employees who have borrowed all books published by McGraw-Hill. c. For each publisher, print the names of employees who have borrowed more than five books of that publisher. 7/11/2016 12Prepared By- Shimul & Hirok,CSE,MBSTU
  • 13. Solution of Problem 2 (a) Print the names of employees who have borrowed any book published by McGraw-Hill. Table: employee Table: books Table: loan 7/11/2016 13Prepared By- Shimul & Hirok,CSE,MBSTU
  • 14. Solution of Problem 2 (a) (cont…) • Query: select distinct name as employee_name from employee inner join loan on employee.emp_no=loan.emp_no inner join books on loan.isbn=books.isbn where books.publisher='Mcgraw-hill'; • Table view: 7/11/2016 14Prepared By- Shimul & Hirok,CSE,MBSTU
  • 15. Solution of Problem 2 (b) Print the names of employees who have borrowed all book published by McGraw-Hill. Table: employee Table: books Table: loan result 7/11/2016 15Prepared By- Shimul & Hirok,CSE,MBSTU
  • 16. Solution of Problem 2 (b) (cont…) • Query: select distinct name as employee_name from employee inner join loan on employee.emp_no=loan.emp_no inner join books on loan.isbn=books.isbn where (select count(loan.isbn) from loan where loan.emp_no=employee.emp_no)=(select count(books.isbn) from books where books.publisher='Mcgraw-hill'); • Table view: 7/11/2016 16Prepared By- Shimul & Hirok,CSE,MBSTU
  • 17. Solution of Problem 2 (c) For each publisher, print the names of employees who have borrowed more than five books of that publisher. Table: employee Table: books Table: loan result More than 5 Books from Mcgraw-hill (only) 7/11/2016 17Prepared By- Shimul & Hirok,CSE,MBSTU
  • 18. Solution of Problem 2 (c) (cont…) • Query: select name from employee,loan,books where employee.emp_no=loan.emp_no and books.isbn=loan.isbn group by employee.emp_no,name,books.publisher having count(loan.isbn) >=5; • Table view: 7/11/2016 18Prepared By- Shimul & Hirok,CSE,MBSTU
  • 19. Problem 3 : Consider the relational schema student(student_id , student_name) registerd(student_id , course_id) Write an SQL query to list the student-id and name of each student along with the total number of courses that the student is registered for. Students who are not registerd for any course must also be listed, with the number of registerd courses shown as 0. 7/11/2016 19Prepared By- Shimul & Hirok,CSE,MBSTU
  • 20. Solution of Problem 3 Table: student Table: registerd a is registerd by 3 course b is registerd by 1 course C is not registerd (0) 7/11/2016 20Prepared By- Shimul & Hirok,CSE,MBSTU
  • 21. Solution of Problem 3 (cont…) • Query: select student_id,student_name,(select count(registerd.course_id) from registerd where student.student_id=registerd.student_id) as taken_course from student; • Table view: 7/11/2016 21Prepared By- Shimul & Hirok,CSE,MBSTU
  • 22. Problem 4: Consider the relational schema: Department (Department _ID , Department _Name) Employee (Employee_ID , Employee_Name,Employee_Age) Employee _Department( Employee _ID , Department _ID ) Salary (Salary _Scale , Salary _Amount) Employee_ Salary (Employee _ID , Salary _Scale) a) Find the Department_names where the employee’s average salary is more than 10000. b) Find the employee_names who has paid in salary scale 1. c) Update the employee ages by increasing 10 years whose ages are not equal to average age. 7/11/2016 22Prepared By- Shimul & Hirok,CSE,MBSTU
  • 23. Solution of Problem 4 (a) Find the Department_names where the employee’s average salary is more than 10000. Table: department Table: employee_department Table: employee_salary Table: salary 7/11/2016 23Prepared By- Shimul & Hirok,CSE,MBSTU
  • 24. Solution of Problem 4(a) (cont…) • Query: select department_name,avg(salary.salary_amount) from department inner join employee_department on department.department_id=employee_department.department_id inner join employee_salary on employee_department.employee_id=employee_salary.employee_id inner join salary on salary.salary_scale=employee_salary.salary_scale having avg(salary.salary_amount)>10000 group by department.department_name; • Table view: 7/11/2016 24Prepared By- Shimul & Hirok,CSE,MBSTU
  • 25. Solution of Problem 4 (b) Find the employee_names who has paid in salary scale 1. Table: Employee Table: employee_salary Table: salary result 7/11/2016 25Prepared By- Shimul & Hirok,CSE,MBSTU
  • 26. Solution of Problem 4(b) (cont…) • Query: select employee_name from employee inner join employee_salary on employee_salary.employee_id=employee.employee_id inner join salary on salary.salary_scale=employee_salary.salary_scale where salary.salary_scale=1; • Table view: 7/11/2016 26Prepared By- Shimul & Hirok,CSE,MBSTU
  • 27. Solution of Problem 4(c) • Query: update employee set employee.employee_age=employee.employee_age+1 where employee.employee_age not in (select avg(employee.employee_age) from employee); • Table view: Before update: After update: Average age 7/11/2016 27Prepared By- Shimul & Hirok,CSE,MBSTU
  • 28. Problem 5 Construct an E-R diagram for a hospital with a set of patients and a set of medical doctors. Associate with each patient a log of the various tests and examinations conducted. 7/11/2016 28Prepared By- Shimul & Hirok,CSE,MBSTU
  • 29. Solution Of problem 5: Fig: E-R diagram for a hospital system. 7/11/2016 29Prepared By- Shimul & Hirok,CSE,MBSTU
  • 30. Problem 6 Draw the UML equivalents of the E-R diagrams Of Figures 6.8c,6.9,6.17,6.72,And 6.20. 7/11/2016 30Prepared By- Shimul & Hirok,CSE,MBSTU
  • 31. Needed Figure of Problem 6 And Its Solution Given……………………. 7/11/2016 31Prepared By- Shimul & Hirok,CSE,MBSTU
  • 32. Fig:6.8c Relationship(One –to-one) Solution of Fig 6.8c: 7/11/2016 32Prepared By- Shimul & Hirok,CSE,MBSTU
  • 33. Solution of Fig 6.9: 7/11/2016 33Prepared By- Shimul & Hirok,CSE,MBSTU
  • 34. Solution of Fig 6.11: 7/11/2016 34Prepared By- Shimul & Hirok,CSE,MBSTU
  • 35. Solution of Fig 6.12: 7/11/2016 35Prepared By- Shimul & Hirok,CSE,MBSTU
  • 36. 7/11/2016 36Prepared By- Shimul & Hirok,CSE,MBSTU
  • 37. Solution of Fig 6.20(Cont….) 7/11/2016 37Prepared By- Shimul & Hirok,CSE,MBSTU
  • 38. THANK YOU 7/11/2016 Prepared By- Shimul & Hirok,CSE,MBSTU 38