SlideShare uma empresa Scribd logo
1 de 30
Baixar para ler offline
QUERY DESIGN
Higher Computing Science
CAR HIRE DATABASE EXAMPLE
• The following SQL query designs will relate to a car hire database which
consists of 4 tables:
Customer Booking Car Depot
places contain
s
is stored at
CAR HIRE DATABASE EXAMPLE
• The following SQL query designs will relate to a car hire database which
consists of 4 tables:
Customer
customerID
forename
surname
telephone
houseNum
postcode
Booking
bookingRef
customerID *
registration *
daysBooked
startDate
Car
registration
make
model
colour
depotID *
automatic
dailyPrice
mileage
Depot
depotID
depotName
depotCity
onlineBookin
g
depotHours
employees
QUERY DESIGN
Field(s) and calculation(s)
Table(s) and query
Search criteria
Grouping
Sort order
• Query designs should include the information shown below
• Depending on the query, not all elements need to be filled
EXAMPLE 1
Field(s) and calculation(s)
Table(s) and query
Search criteria
Grouping
Sort order
• Design a query to show the make, model and mileage of a car in a depot
which is open all day, and where the make of car starts with ‘M’.
EXAMPLE 1
Field(s) and calculation(s) make, model, mileage, depotName, depotHours
Table(s) and query car, depot
Search criteria depotHours = ‘All Day’ and model like ‘M%’
Grouping
Sort order
• Design a query to show the make, model, mileage and depot of any car
in a depot that is open all day and where the make of car starts with ‘M’.
EXAMPLE 2
Field(s) and calculation(s)
Table(s) and query
Search criteria
Grouping
Sort order
• Design a query to show a customer’s full name, booking ID, car make and
model, and depot name for all customers who have ‘e’ as the 5th letter of
their surname
• List the details in alphabetical order of the customer surname
EXAMPLE 2
Field(s) and calculation(s) forename, surname, bookingRef, make, model,
depotName
Table(s) and query customer, booking, car, depot
Search criteria surname LIKE = ‘_ _ _ _ e %’
Grouping
Sort order surname ASC
• Design a query to show a customer’s full name, booking ID, car make and
model, and depot name for all customers who have ‘e’ as the 5th letter of
their surname
• List the details in alphabetical order of the customer surname
EXAMPLE 3
Field(s) and calculation(s)
Table(s) and query
Search criteria
Grouping
Sort order
• Design a query to display the average mileage of all cars in the car table.
EXAMPLE 3
Field(s) and calculation(s) AVG(mileage)
Table(s) and query car
Search criteria
Grouping
Sort order
• Design a query to display the average mileage of all cars in the car table.
EXAMPLE 4
Field(s) and calculation(s)
Table(s) and query
Search criteria
Grouping
Sort order
• Design a query that uses a readable heading to display the lowest and
highest mileages of the cars in the car table.
EXAMPLE 4
Field(s) and calculation(s) Lowest Mileage = MIN(mileage),
Highest Mileage = MAX(mileage)
Table(s) and query car
Search criteria
Grouping
Sort order
• Design a query that uses a readable heading to display the lowest and
highest mileages of the cars in the car table.
EXAMPLE 5
Field(s) and calculation(s)
Table(s) and query
Search criteria
Grouping
Sort order
• Design a query to display the cities that have depot, together with the
number of depots in each city.
EXAMPLE 5
Field(s) and calculation(s) depotCity, COUNT(*)
Table(s) and query depot
Search criteria
Grouping depotCity
Sort order
• Design a query to display the cities that have depot, together with the
number of depots in each city.
EXAMPLE 6
Field(s) and calculation(s)
Table(s) and query
Search criteria
Grouping
Sort order
• Design a query to display the number of employees that are based in
depots in Edinburgh or Glasgow. Use ‘Edinburgh/Glasgow Employees’ as
a readable heading.
EXAMPLE 6
Field(s) and calculation(s) Edinburgh/Glasgow Employees = SUM(staff)
Table(s) and query depot
Search criteria depotCity = ‘Edinburgh’ OR depotCity = ‘Glasgow’
Grouping
Sort order
• Design a query to display the number of employees that are based in
depots in Edinburgh or Glasgow. Use ‘Edinburgh/Glasgow Employees’ as
a readable heading.
EXAMPLE 7
Field(s) and calculation(s)
Table(s) and query
Search criteria
Grouping
Sort order
• Design a query to display a list of each car colour, together with the
number of bookings made for cars of those colours.
• List the details from the least popular colour to the most popular colour.
EXAMPLE 7
Field(s) and calculation(s) colour, COUNT(*)
Table(s) and query car, booking
Search criteria
Grouping colour
Sort order COUNT(*) ASC
• Design a query to display a list of each car colour, together with the
number of bookings made for cars of those colours.
• List the details from the least popular colour to the most popular colour.
EXAMPLE 8
Field(s) and calculation(s)
Table(s) and query
Search criteria
Grouping
Sort order
• Design a query that uses a readable heading to display the total number
of days cars have been booked out during May.
EXAMPLE 8
Field(s) and calculation(s) Days cars booked in May = SUM(daysBooked)
Table(s) and query booking
Search criteria startDate LIKE ‘%/05/%’
Grouping
Sort order
• Design a query that uses a readable heading to display the total number
of days cars have been booked out during May.
EXAMPLE 9
Field(s) and calculation(s)
Table(s) and query
Search criteria
Grouping
Sort order
• Design a query to display the car registration and increased price, if all
the cars from the Inverness depot increase their daily price by £5.
EXAMPLE 9
Field(s) and calculation(s) registration, Increased Price = dailyPrice + 5
Table(s) and query car, depot
Search criteria depotCity = ‘Inverness’
Grouping
Sort order
• Design a query to display the car registration and increased price, if all
the cars from the Inverness depot increase their daily price by £5.
EXAMPLE 10
Field(s) and calculation(s)
Table(s) and query
Search criteria
Grouping
Sort order
• Design a query to display the surname, booking reference, number of
days booked, daily price, and a calculated total cost of each booking
(with a readable column heading).
• Display the most expensive booking first.
EXAMPLE 10
Field(s) and calculation(s) surname, bookingRef, daysBooked, dailyPrice,
Total Cost = daysBooked * dailyPrice
Table(s) and query customer, booking, car
Search criteria
Grouping
Sort order daysBooked * dailyPrice DESC
• Design a query to display the surname, booking reference, number of
days booked, daily price, and a calculated total cost of each booking
(with a readable column heading).
• Display the most expensive booking first.
EXAMPLE 11
• Design a query to display the name of depots that have cars with the
cheapest daily price together with the price (use a readable heading to
display the cheapest price).
• Since it is not possible to use an aggregate function in a WHERE clause,
this solution requires two separate queries.
• Query 1: a simple query to generate a single value (the cheapest daily price)
• Query 2: uses Query 1 to find the depots with the cheapest daily price
EXAMPLE 11
Query 1 – Find Minimum Daily Price
Field(s) and calculation(s) Cheapest Daily Price = MIN(dailyPrice)
Table(s) and query car
Search criteria
Grouping
Sort order
• Design a query to display the name of depots that have cars with the
cheapest daily price together with the price (use a readable heading to
display the cheapest price).
EXAMPLE 11
Query 2 – Display names of depots with cars at cheapest daily price
Field(s) and calculation(s) depotName, Cheapest Daily Price
Table(s) and query car, depot, Find Minimum Daily Price
Search criteria dailyPrice = Cheapest Daily Price
Grouping
Sort order
• Design a query to display the name of depots that have cars with the
cheapest daily price together with the price (use a readable heading to
display the cheapest price).
EXAMPLE 12
• Design a query to display the details of any automatic car with a daily
price that is above the average daily price. The query should display the
car make, model, colour, automatic and daily price.
• The most expensive cars should be listed first.
• This solution requires two separate queries.
• Query 1: a simple query to generate a single value (the average daily price)
• Query 2: uses Query 1 to find the automatic cars that are above the average
daily price
EXAMPLE 12
Query 1 – Find Average Daily Price
Field(s) and calculation(s) Average Daily Price = AVG(dailyPrice)
Table(s) and query car
Search criteria
Grouping
Sort order
• Design a query to display the details of any automatic car with a daily
price that is above the average daily price. The query should display the
car make, model, colour, automatic and daily price.
• The most expensive cars should be listed first.
EXAMPLE 12
Query 2 – Display automatic cars with daily price above average daily price
Field(s) and calculation(s) make, model, colour, automatic, dailyPrice,
Average Daily Price
Table(s) and query car, Find Average Daily Price
Search criteria dailyPrice > Average Daily Price and automatic =
TRUE
Grouping
Sort order dailyPrice DESC
• Design a query to display the details of any automatic car with a daily
price that is above the average daily price. The query should display the
car make, model, colour, automatic and daily price.
• The most expensive cars should be listed first.

Mais conteúdo relacionado

Mais procurados

Sql queries presentation
Sql queries presentationSql queries presentation
Sql queries presentationNITISH KUMAR
 
SQL - DML and DDL Commands
SQL - DML and DDL CommandsSQL - DML and DDL Commands
SQL - DML and DDL CommandsShrija Madhu
 
Introduction to structured query language (sql)
Introduction to structured query language (sql)Introduction to structured query language (sql)
Introduction to structured query language (sql)Sabana Maharjan
 
Structured query language
Structured query languageStructured query language
Structured query languageRashid Ansari
 
Indexes and Indexing in Oracle 12c
Indexes and Indexing in Oracle 12cIndexes and Indexing in Oracle 12c
Indexes and Indexing in Oracle 12cOren Nakdimon
 
SQL Tutorial - Basic Commands
SQL Tutorial - Basic CommandsSQL Tutorial - Basic Commands
SQL Tutorial - Basic Commands1keydata
 
SQL Functions and Operators
SQL Functions and OperatorsSQL Functions and Operators
SQL Functions and OperatorsMohan Kumar.R
 
Sql – Structured Query Language
Sql – Structured Query LanguageSql – Structured Query Language
Sql – Structured Query Languagepandey3045_bit
 
Aggregate functions in SQL.pptx
Aggregate functions in SQL.pptxAggregate functions in SQL.pptx
Aggregate functions in SQL.pptxSherinRappai
 
sql function(ppt)
sql function(ppt)sql function(ppt)
sql function(ppt)Ankit Dubey
 
Getting Started with MySQL I
Getting Started with MySQL IGetting Started with MySQL I
Getting Started with MySQL ISankhya_Analytics
 

Mais procurados (20)

Sql and Sql commands
Sql and Sql commandsSql and Sql commands
Sql and Sql commands
 
Sql queries presentation
Sql queries presentationSql queries presentation
Sql queries presentation
 
SQL - DML and DDL Commands
SQL - DML and DDL CommandsSQL - DML and DDL Commands
SQL - DML and DDL Commands
 
SQL
SQLSQL
SQL
 
Introduction to structured query language (sql)
Introduction to structured query language (sql)Introduction to structured query language (sql)
Introduction to structured query language (sql)
 
Sql tutorial
Sql tutorialSql tutorial
Sql tutorial
 
Introduction to sql
Introduction to sqlIntroduction to sql
Introduction to sql
 
SQL
SQLSQL
SQL
 
Structured query language
Structured query languageStructured query language
Structured query language
 
Indexes and Indexing in Oracle 12c
Indexes and Indexing in Oracle 12cIndexes and Indexing in Oracle 12c
Indexes and Indexing in Oracle 12c
 
SQL
SQLSQL
SQL
 
SQL
SQLSQL
SQL
 
SQL Tutorial - Basic Commands
SQL Tutorial - Basic CommandsSQL Tutorial - Basic Commands
SQL Tutorial - Basic Commands
 
SQL Functions and Operators
SQL Functions and OperatorsSQL Functions and Operators
SQL Functions and Operators
 
Introduction to database
Introduction to databaseIntroduction to database
Introduction to database
 
Sql - Structured Query Language
Sql - Structured Query LanguageSql - Structured Query Language
Sql - Structured Query Language
 
Sql – Structured Query Language
Sql – Structured Query LanguageSql – Structured Query Language
Sql – Structured Query Language
 
Aggregate functions in SQL.pptx
Aggregate functions in SQL.pptxAggregate functions in SQL.pptx
Aggregate functions in SQL.pptx
 
sql function(ppt)
sql function(ppt)sql function(ppt)
sql function(ppt)
 
Getting Started with MySQL I
Getting Started with MySQL IGetting Started with MySQL I
Getting Started with MySQL I
 

Semelhante a Database Query Design

Predicting model for prices of used cars
Predicting model for prices of used carsPredicting model for prices of used cars
Predicting model for prices of used carsHARPREETSINGH1862
 
Data Analytics Project Presentation
Data Analytics Project PresentationData Analytics Project Presentation
Data Analytics Project PresentationRohit Vaze
 
Lesson objectives unit 6 advanced databases
Lesson objectives unit 6 advanced databasesLesson objectives unit 6 advanced databases
Lesson objectives unit 6 advanced databasesGavin McIntyre
 
CARVANA - Predicting the purchase quality in car
CARVANA - Predicting the  purchase quality in carCARVANA - Predicting the  purchase quality in car
CARVANA - Predicting the purchase quality in carShankarPrasaadRajama
 
Semantic search in databases
Semantic search in databasesSemantic search in databases
Semantic search in databasesTomáš Drenčák
 
Using machine learning to generate predictions based on the information extra...
Using machine learning to generate predictions based on the information extra...Using machine learning to generate predictions based on the information extra...
Using machine learning to generate predictions based on the information extra...University Politehnica Bucharest
 
MongoDB World 2016 : Advanced Aggregation
MongoDB World 2016 : Advanced AggregationMongoDB World 2016 : Advanced Aggregation
MongoDB World 2016 : Advanced AggregationJoe Drumgoole
 
Darden School of Business Tesla Strategic Analysis
Darden School of Business   Tesla Strategic AnalysisDarden School of Business   Tesla Strategic Analysis
Darden School of Business Tesla Strategic AnalysisJosé Ángel Álvarez Fuente
 
Data Warehouse and OLAP - Lear-Fabini
Data Warehouse and OLAP - Lear-FabiniData Warehouse and OLAP - Lear-Fabini
Data Warehouse and OLAP - Lear-FabiniScott Fabini
 
R, Scikit-Learn and Apache Spark ML - What difference does it make?
R, Scikit-Learn and Apache Spark ML - What difference does it make?R, Scikit-Learn and Apache Spark ML - What difference does it make?
R, Scikit-Learn and Apache Spark ML - What difference does it make?Villu Ruusmann
 
SmirnovGarciaFinalProject
SmirnovGarciaFinalProjectSmirnovGarciaFinalProject
SmirnovGarciaFinalProjectDenis Smirnov
 
http://boxinglatestnews.com
http://boxinglatestnews.comhttp://boxinglatestnews.com
http://boxinglatestnews.comDavid Lopez
 
WRITTEN INTERVIEW QUESTIONSDoctoral candidates shoul.docx
WRITTEN INTERVIEW QUESTIONSDoctoral candidates shoul.docxWRITTEN INTERVIEW QUESTIONSDoctoral candidates shoul.docx
WRITTEN INTERVIEW QUESTIONSDoctoral candidates shoul.docxodiliagilby
 
4th Auto Remarketing Forum India 2017
4th Auto Remarketing Forum India 20174th Auto Remarketing Forum India 2017
4th Auto Remarketing Forum India 2017Ilana Kearns
 

Semelhante a Database Query Design (20)

SQL
SQLSQL
SQL
 
Database Analysis
Database AnalysisDatabase Analysis
Database Analysis
 
Database Analysis
Database AnalysisDatabase Analysis
Database Analysis
 
Predicting model for prices of used cars
Predicting model for prices of used carsPredicting model for prices of used cars
Predicting model for prices of used cars
 
Data Analytics Project Presentation
Data Analytics Project PresentationData Analytics Project Presentation
Data Analytics Project Presentation
 
Lesson objectives unit 6 advanced databases
Lesson objectives unit 6 advanced databasesLesson objectives unit 6 advanced databases
Lesson objectives unit 6 advanced databases
 
CARVANA - Predicting the purchase quality in car
CARVANA - Predicting the  purchase quality in carCARVANA - Predicting the  purchase quality in car
CARVANA - Predicting the purchase quality in car
 
Semantic search in databases
Semantic search in databasesSemantic search in databases
Semantic search in databases
 
Using machine learning to generate predictions based on the information extra...
Using machine learning to generate predictions based on the information extra...Using machine learning to generate predictions based on the information extra...
Using machine learning to generate predictions based on the information extra...
 
MongoDB World 2016 : Advanced Aggregation
MongoDB World 2016 : Advanced AggregationMongoDB World 2016 : Advanced Aggregation
MongoDB World 2016 : Advanced Aggregation
 
Darden School of Business Tesla Strategic Analysis
Darden School of Business   Tesla Strategic AnalysisDarden School of Business   Tesla Strategic Analysis
Darden School of Business Tesla Strategic Analysis
 
Automotive-new
Automotive-newAutomotive-new
Automotive-new
 
Data Warehouse and OLAP - Lear-Fabini
Data Warehouse and OLAP - Lear-FabiniData Warehouse and OLAP - Lear-Fabini
Data Warehouse and OLAP - Lear-Fabini
 
R, Scikit-Learn and Apache Spark ML - What difference does it make?
R, Scikit-Learn and Apache Spark ML - What difference does it make?R, Scikit-Learn and Apache Spark ML - What difference does it make?
R, Scikit-Learn and Apache Spark ML - What difference does it make?
 
SmirnovGarciaFinalProject
SmirnovGarciaFinalProjectSmirnovGarciaFinalProject
SmirnovGarciaFinalProject
 
http://boxinglatestnews.com
http://boxinglatestnews.comhttp://boxinglatestnews.com
http://boxinglatestnews.com
 
Testing SQL
Testing SQLTesting SQL
Testing SQL
 
WRITTEN INTERVIEW QUESTIONSDoctoral candidates shoul.docx
WRITTEN INTERVIEW QUESTIONSDoctoral candidates shoul.docxWRITTEN INTERVIEW QUESTIONSDoctoral candidates shoul.docx
WRITTEN INTERVIEW QUESTIONSDoctoral candidates shoul.docx
 
4th Autoremarketing Forum India 2017
4th Autoremarketing Forum India 20174th Autoremarketing Forum India 2017
4th Autoremarketing Forum India 2017
 
4th Auto Remarketing Forum India 2017
4th Auto Remarketing Forum India 20174th Auto Remarketing Forum India 2017
4th Auto Remarketing Forum India 2017
 

Mais de Forrester High School (20)

Program Design
Program DesignProgram Design
Program Design
 
Database Evaluation
Database EvaluationDatabase Evaluation
Database Evaluation
 
Data Dictionary
Data DictionaryData Dictionary
Data Dictionary
 
Compound Keys
Compound KeysCompound Keys
Compound Keys
 
Entity Occurrence Diagrams
Entity Occurrence DiagramsEntity Occurrence Diagrams
Entity Occurrence Diagrams
 
Entity Relationship Diagrams
Entity Relationship DiagramsEntity Relationship Diagrams
Entity Relationship Diagrams
 
Database Analysis
Database AnalysisDatabase Analysis
Database Analysis
 
Software Evaluation
Software EvaluationSoftware Evaluation
Software Evaluation
 
Software Testing
Software TestingSoftware Testing
Software Testing
 
Standard Algorithms
Standard AlgorithmsStandard Algorithms
Standard Algorithms
 
File Handling
File HandlingFile Handling
File Handling
 
Python Predefined Functions
Python Predefined FunctionsPython Predefined Functions
Python Predefined Functions
 
Python Substrings
Python SubstringsPython Substrings
Python Substrings
 
Variable Scope
Variable ScopeVariable Scope
Variable Scope
 
Sub-programs
Sub-programsSub-programs
Sub-programs
 
Records in Python
Records in PythonRecords in Python
Records in Python
 
Parallel arrays in python
Parallel arrays in pythonParallel arrays in python
Parallel arrays in python
 
SDD Predefined Functions
SDD Predefined FunctionsSDD Predefined Functions
SDD Predefined Functions
 
SDD Cconditional Loops
SDD Cconditional LoopsSDD Cconditional Loops
SDD Cconditional Loops
 
SDD Fixed Loops
SDD Fixed LoopsSDD Fixed Loops
SDD Fixed Loops
 

Último

Maximizing Impact_ Nonprofit Website Planning, Budgeting, and Design.pdf
Maximizing Impact_ Nonprofit Website Planning, Budgeting, and Design.pdfMaximizing Impact_ Nonprofit Website Planning, Budgeting, and Design.pdf
Maximizing Impact_ Nonprofit Website Planning, Budgeting, and Design.pdfTechSoup
 
Patient Counselling. Definition of patient counseling; steps involved in pati...
Patient Counselling. Definition of patient counseling; steps involved in pati...Patient Counselling. Definition of patient counseling; steps involved in pati...
Patient Counselling. Definition of patient counseling; steps involved in pati...raviapr7
 
General views of Histopathology and step
General views of Histopathology and stepGeneral views of Histopathology and step
General views of Histopathology and stepobaje godwin sunday
 
P4C x ELT = P4ELT: Its Theoretical Background (Kanazawa, 2024 March).pdf
P4C x ELT = P4ELT: Its Theoretical Background (Kanazawa, 2024 March).pdfP4C x ELT = P4ELT: Its Theoretical Background (Kanazawa, 2024 March).pdf
P4C x ELT = P4ELT: Its Theoretical Background (Kanazawa, 2024 March).pdfYu Kanazawa / Osaka University
 
Benefits & Challenges of Inclusive Education
Benefits & Challenges of Inclusive EducationBenefits & Challenges of Inclusive Education
Benefits & Challenges of Inclusive EducationMJDuyan
 
Quality Assurance_GOOD LABORATORY PRACTICE
Quality Assurance_GOOD LABORATORY PRACTICEQuality Assurance_GOOD LABORATORY PRACTICE
Quality Assurance_GOOD LABORATORY PRACTICESayali Powar
 
Drug Information Services- DIC and Sources.
Drug Information Services- DIC and Sources.Drug Information Services- DIC and Sources.
Drug Information Services- DIC and Sources.raviapr7
 
M-2- General Reactions of amino acids.pptx
M-2- General Reactions of amino acids.pptxM-2- General Reactions of amino acids.pptx
M-2- General Reactions of amino acids.pptxDr. Santhosh Kumar. N
 
In - Vivo and In - Vitro Correlation.pptx
In - Vivo and In - Vitro Correlation.pptxIn - Vivo and In - Vitro Correlation.pptx
In - Vivo and In - Vitro Correlation.pptxAditiChauhan701637
 
How to Make a Field read-only in Odoo 17
How to Make a Field read-only in Odoo 17How to Make a Field read-only in Odoo 17
How to Make a Field read-only in Odoo 17Celine George
 
How to Show Error_Warning Messages in Odoo 17
How to Show Error_Warning Messages in Odoo 17How to Show Error_Warning Messages in Odoo 17
How to Show Error_Warning Messages in Odoo 17Celine George
 
HED Office Sohayok Exam Question Solution 2023.pdf
HED Office Sohayok Exam Question Solution 2023.pdfHED Office Sohayok Exam Question Solution 2023.pdf
HED Office Sohayok Exam Question Solution 2023.pdfMohonDas
 
The basics of sentences session 10pptx.pptx
The basics of sentences session 10pptx.pptxThe basics of sentences session 10pptx.pptx
The basics of sentences session 10pptx.pptxheathfieldcps1
 
Education and training program in the hospital APR.pptx
Education and training program in the hospital APR.pptxEducation and training program in the hospital APR.pptx
Education and training program in the hospital APR.pptxraviapr7
 
Patterns of Written Texts Across Disciplines.pptx
Patterns of Written Texts Across Disciplines.pptxPatterns of Written Texts Across Disciplines.pptx
Patterns of Written Texts Across Disciplines.pptxMYDA ANGELICA SUAN
 
CapTechU Doctoral Presentation -March 2024 slides.pptx
CapTechU Doctoral Presentation -March 2024 slides.pptxCapTechU Doctoral Presentation -March 2024 slides.pptx
CapTechU Doctoral Presentation -March 2024 slides.pptxCapitolTechU
 
Prescribed medication order and communication skills.pptx
Prescribed medication order and communication skills.pptxPrescribed medication order and communication skills.pptx
Prescribed medication order and communication skills.pptxraviapr7
 
Diploma in Nursing Admission Test Question Solution 2023.pdf
Diploma in Nursing Admission Test Question Solution 2023.pdfDiploma in Nursing Admission Test Question Solution 2023.pdf
Diploma in Nursing Admission Test Question Solution 2023.pdfMohonDas
 
PISA-VET launch_El Iza Mohamedou_19 March 2024.pptx
PISA-VET launch_El Iza Mohamedou_19 March 2024.pptxPISA-VET launch_El Iza Mohamedou_19 March 2024.pptx
PISA-VET launch_El Iza Mohamedou_19 March 2024.pptxEduSkills OECD
 

Último (20)

Maximizing Impact_ Nonprofit Website Planning, Budgeting, and Design.pdf
Maximizing Impact_ Nonprofit Website Planning, Budgeting, and Design.pdfMaximizing Impact_ Nonprofit Website Planning, Budgeting, and Design.pdf
Maximizing Impact_ Nonprofit Website Planning, Budgeting, and Design.pdf
 
Patient Counselling. Definition of patient counseling; steps involved in pati...
Patient Counselling. Definition of patient counseling; steps involved in pati...Patient Counselling. Definition of patient counseling; steps involved in pati...
Patient Counselling. Definition of patient counseling; steps involved in pati...
 
General views of Histopathology and step
General views of Histopathology and stepGeneral views of Histopathology and step
General views of Histopathology and step
 
P4C x ELT = P4ELT: Its Theoretical Background (Kanazawa, 2024 March).pdf
P4C x ELT = P4ELT: Its Theoretical Background (Kanazawa, 2024 March).pdfP4C x ELT = P4ELT: Its Theoretical Background (Kanazawa, 2024 March).pdf
P4C x ELT = P4ELT: Its Theoretical Background (Kanazawa, 2024 March).pdf
 
Benefits & Challenges of Inclusive Education
Benefits & Challenges of Inclusive EducationBenefits & Challenges of Inclusive Education
Benefits & Challenges of Inclusive Education
 
Quality Assurance_GOOD LABORATORY PRACTICE
Quality Assurance_GOOD LABORATORY PRACTICEQuality Assurance_GOOD LABORATORY PRACTICE
Quality Assurance_GOOD LABORATORY PRACTICE
 
Drug Information Services- DIC and Sources.
Drug Information Services- DIC and Sources.Drug Information Services- DIC and Sources.
Drug Information Services- DIC and Sources.
 
M-2- General Reactions of amino acids.pptx
M-2- General Reactions of amino acids.pptxM-2- General Reactions of amino acids.pptx
M-2- General Reactions of amino acids.pptx
 
In - Vivo and In - Vitro Correlation.pptx
In - Vivo and In - Vitro Correlation.pptxIn - Vivo and In - Vitro Correlation.pptx
In - Vivo and In - Vitro Correlation.pptx
 
Prelims of Kant get Marx 2.0: a general politics quiz
Prelims of Kant get Marx 2.0: a general politics quizPrelims of Kant get Marx 2.0: a general politics quiz
Prelims of Kant get Marx 2.0: a general politics quiz
 
How to Make a Field read-only in Odoo 17
How to Make a Field read-only in Odoo 17How to Make a Field read-only in Odoo 17
How to Make a Field read-only in Odoo 17
 
How to Show Error_Warning Messages in Odoo 17
How to Show Error_Warning Messages in Odoo 17How to Show Error_Warning Messages in Odoo 17
How to Show Error_Warning Messages in Odoo 17
 
HED Office Sohayok Exam Question Solution 2023.pdf
HED Office Sohayok Exam Question Solution 2023.pdfHED Office Sohayok Exam Question Solution 2023.pdf
HED Office Sohayok Exam Question Solution 2023.pdf
 
The basics of sentences session 10pptx.pptx
The basics of sentences session 10pptx.pptxThe basics of sentences session 10pptx.pptx
The basics of sentences session 10pptx.pptx
 
Education and training program in the hospital APR.pptx
Education and training program in the hospital APR.pptxEducation and training program in the hospital APR.pptx
Education and training program in the hospital APR.pptx
 
Patterns of Written Texts Across Disciplines.pptx
Patterns of Written Texts Across Disciplines.pptxPatterns of Written Texts Across Disciplines.pptx
Patterns of Written Texts Across Disciplines.pptx
 
CapTechU Doctoral Presentation -March 2024 slides.pptx
CapTechU Doctoral Presentation -March 2024 slides.pptxCapTechU Doctoral Presentation -March 2024 slides.pptx
CapTechU Doctoral Presentation -March 2024 slides.pptx
 
Prescribed medication order and communication skills.pptx
Prescribed medication order and communication skills.pptxPrescribed medication order and communication skills.pptx
Prescribed medication order and communication skills.pptx
 
Diploma in Nursing Admission Test Question Solution 2023.pdf
Diploma in Nursing Admission Test Question Solution 2023.pdfDiploma in Nursing Admission Test Question Solution 2023.pdf
Diploma in Nursing Admission Test Question Solution 2023.pdf
 
PISA-VET launch_El Iza Mohamedou_19 March 2024.pptx
PISA-VET launch_El Iza Mohamedou_19 March 2024.pptxPISA-VET launch_El Iza Mohamedou_19 March 2024.pptx
PISA-VET launch_El Iza Mohamedou_19 March 2024.pptx
 

Database Query Design

  • 2. CAR HIRE DATABASE EXAMPLE • The following SQL query designs will relate to a car hire database which consists of 4 tables: Customer Booking Car Depot places contain s is stored at
  • 3. CAR HIRE DATABASE EXAMPLE • The following SQL query designs will relate to a car hire database which consists of 4 tables: Customer customerID forename surname telephone houseNum postcode Booking bookingRef customerID * registration * daysBooked startDate Car registration make model colour depotID * automatic dailyPrice mileage Depot depotID depotName depotCity onlineBookin g depotHours employees
  • 4. QUERY DESIGN Field(s) and calculation(s) Table(s) and query Search criteria Grouping Sort order • Query designs should include the information shown below • Depending on the query, not all elements need to be filled
  • 5. EXAMPLE 1 Field(s) and calculation(s) Table(s) and query Search criteria Grouping Sort order • Design a query to show the make, model and mileage of a car in a depot which is open all day, and where the make of car starts with ‘M’.
  • 6. EXAMPLE 1 Field(s) and calculation(s) make, model, mileage, depotName, depotHours Table(s) and query car, depot Search criteria depotHours = ‘All Day’ and model like ‘M%’ Grouping Sort order • Design a query to show the make, model, mileage and depot of any car in a depot that is open all day and where the make of car starts with ‘M’.
  • 7. EXAMPLE 2 Field(s) and calculation(s) Table(s) and query Search criteria Grouping Sort order • Design a query to show a customer’s full name, booking ID, car make and model, and depot name for all customers who have ‘e’ as the 5th letter of their surname • List the details in alphabetical order of the customer surname
  • 8. EXAMPLE 2 Field(s) and calculation(s) forename, surname, bookingRef, make, model, depotName Table(s) and query customer, booking, car, depot Search criteria surname LIKE = ‘_ _ _ _ e %’ Grouping Sort order surname ASC • Design a query to show a customer’s full name, booking ID, car make and model, and depot name for all customers who have ‘e’ as the 5th letter of their surname • List the details in alphabetical order of the customer surname
  • 9. EXAMPLE 3 Field(s) and calculation(s) Table(s) and query Search criteria Grouping Sort order • Design a query to display the average mileage of all cars in the car table.
  • 10. EXAMPLE 3 Field(s) and calculation(s) AVG(mileage) Table(s) and query car Search criteria Grouping Sort order • Design a query to display the average mileage of all cars in the car table.
  • 11. EXAMPLE 4 Field(s) and calculation(s) Table(s) and query Search criteria Grouping Sort order • Design a query that uses a readable heading to display the lowest and highest mileages of the cars in the car table.
  • 12. EXAMPLE 4 Field(s) and calculation(s) Lowest Mileage = MIN(mileage), Highest Mileage = MAX(mileage) Table(s) and query car Search criteria Grouping Sort order • Design a query that uses a readable heading to display the lowest and highest mileages of the cars in the car table.
  • 13. EXAMPLE 5 Field(s) and calculation(s) Table(s) and query Search criteria Grouping Sort order • Design a query to display the cities that have depot, together with the number of depots in each city.
  • 14. EXAMPLE 5 Field(s) and calculation(s) depotCity, COUNT(*) Table(s) and query depot Search criteria Grouping depotCity Sort order • Design a query to display the cities that have depot, together with the number of depots in each city.
  • 15. EXAMPLE 6 Field(s) and calculation(s) Table(s) and query Search criteria Grouping Sort order • Design a query to display the number of employees that are based in depots in Edinburgh or Glasgow. Use ‘Edinburgh/Glasgow Employees’ as a readable heading.
  • 16. EXAMPLE 6 Field(s) and calculation(s) Edinburgh/Glasgow Employees = SUM(staff) Table(s) and query depot Search criteria depotCity = ‘Edinburgh’ OR depotCity = ‘Glasgow’ Grouping Sort order • Design a query to display the number of employees that are based in depots in Edinburgh or Glasgow. Use ‘Edinburgh/Glasgow Employees’ as a readable heading.
  • 17. EXAMPLE 7 Field(s) and calculation(s) Table(s) and query Search criteria Grouping Sort order • Design a query to display a list of each car colour, together with the number of bookings made for cars of those colours. • List the details from the least popular colour to the most popular colour.
  • 18. EXAMPLE 7 Field(s) and calculation(s) colour, COUNT(*) Table(s) and query car, booking Search criteria Grouping colour Sort order COUNT(*) ASC • Design a query to display a list of each car colour, together with the number of bookings made for cars of those colours. • List the details from the least popular colour to the most popular colour.
  • 19. EXAMPLE 8 Field(s) and calculation(s) Table(s) and query Search criteria Grouping Sort order • Design a query that uses a readable heading to display the total number of days cars have been booked out during May.
  • 20. EXAMPLE 8 Field(s) and calculation(s) Days cars booked in May = SUM(daysBooked) Table(s) and query booking Search criteria startDate LIKE ‘%/05/%’ Grouping Sort order • Design a query that uses a readable heading to display the total number of days cars have been booked out during May.
  • 21. EXAMPLE 9 Field(s) and calculation(s) Table(s) and query Search criteria Grouping Sort order • Design a query to display the car registration and increased price, if all the cars from the Inverness depot increase their daily price by £5.
  • 22. EXAMPLE 9 Field(s) and calculation(s) registration, Increased Price = dailyPrice + 5 Table(s) and query car, depot Search criteria depotCity = ‘Inverness’ Grouping Sort order • Design a query to display the car registration and increased price, if all the cars from the Inverness depot increase their daily price by £5.
  • 23. EXAMPLE 10 Field(s) and calculation(s) Table(s) and query Search criteria Grouping Sort order • Design a query to display the surname, booking reference, number of days booked, daily price, and a calculated total cost of each booking (with a readable column heading). • Display the most expensive booking first.
  • 24. EXAMPLE 10 Field(s) and calculation(s) surname, bookingRef, daysBooked, dailyPrice, Total Cost = daysBooked * dailyPrice Table(s) and query customer, booking, car Search criteria Grouping Sort order daysBooked * dailyPrice DESC • Design a query to display the surname, booking reference, number of days booked, daily price, and a calculated total cost of each booking (with a readable column heading). • Display the most expensive booking first.
  • 25. EXAMPLE 11 • Design a query to display the name of depots that have cars with the cheapest daily price together with the price (use a readable heading to display the cheapest price). • Since it is not possible to use an aggregate function in a WHERE clause, this solution requires two separate queries. • Query 1: a simple query to generate a single value (the cheapest daily price) • Query 2: uses Query 1 to find the depots with the cheapest daily price
  • 26. EXAMPLE 11 Query 1 – Find Minimum Daily Price Field(s) and calculation(s) Cheapest Daily Price = MIN(dailyPrice) Table(s) and query car Search criteria Grouping Sort order • Design a query to display the name of depots that have cars with the cheapest daily price together with the price (use a readable heading to display the cheapest price).
  • 27. EXAMPLE 11 Query 2 – Display names of depots with cars at cheapest daily price Field(s) and calculation(s) depotName, Cheapest Daily Price Table(s) and query car, depot, Find Minimum Daily Price Search criteria dailyPrice = Cheapest Daily Price Grouping Sort order • Design a query to display the name of depots that have cars with the cheapest daily price together with the price (use a readable heading to display the cheapest price).
  • 28. EXAMPLE 12 • Design a query to display the details of any automatic car with a daily price that is above the average daily price. The query should display the car make, model, colour, automatic and daily price. • The most expensive cars should be listed first. • This solution requires two separate queries. • Query 1: a simple query to generate a single value (the average daily price) • Query 2: uses Query 1 to find the automatic cars that are above the average daily price
  • 29. EXAMPLE 12 Query 1 – Find Average Daily Price Field(s) and calculation(s) Average Daily Price = AVG(dailyPrice) Table(s) and query car Search criteria Grouping Sort order • Design a query to display the details of any automatic car with a daily price that is above the average daily price. The query should display the car make, model, colour, automatic and daily price. • The most expensive cars should be listed first.
  • 30. EXAMPLE 12 Query 2 – Display automatic cars with daily price above average daily price Field(s) and calculation(s) make, model, colour, automatic, dailyPrice, Average Daily Price Table(s) and query car, Find Average Daily Price Search criteria dailyPrice > Average Daily Price and automatic = TRUE Grouping Sort order dailyPrice DESC • Design a query to display the details of any automatic car with a daily price that is above the average daily price. The query should display the car make, model, colour, automatic and daily price. • The most expensive cars should be listed first.