SlideShare a Scribd company logo
1 of 30
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.

More Related Content

What's hot

İleri Seviye T-SQL Programlama - Chapter 04
İleri Seviye T-SQL Programlama - Chapter 04İleri Seviye T-SQL Programlama - Chapter 04
İleri Seviye T-SQL Programlama - Chapter 04Cihan Özhan
 
Express JS Rest API Tutorial
Express JS Rest API TutorialExpress JS Rest API Tutorial
Express JS Rest API TutorialSimplilearn
 
Migration From Oracle to PostgreSQL
Migration From Oracle to PostgreSQLMigration From Oracle to PostgreSQL
Migration From Oracle to PostgreSQLPGConf APAC
 
Regular Expressions 101 Introduction to Regular Expressions
Regular Expressions 101 Introduction to Regular ExpressionsRegular Expressions 101 Introduction to Regular Expressions
Regular Expressions 101 Introduction to Regular ExpressionsDanny Bryant
 
Tricks every ClickHouse designer should know, by Robert Hodges, Altinity CEO
Tricks every ClickHouse designer should know, by Robert Hodges, Altinity CEOTricks every ClickHouse designer should know, by Robert Hodges, Altinity CEO
Tricks every ClickHouse designer should know, by Robert Hodges, Altinity CEOAltinity Ltd
 
Node.js Express Tutorial | Node.js Tutorial For Beginners | Node.js + Expres...
Node.js Express Tutorial | Node.js Tutorial For Beginners | Node.js +  Expres...Node.js Express Tutorial | Node.js Tutorial For Beginners | Node.js +  Expres...
Node.js Express Tutorial | Node.js Tutorial For Beginners | Node.js + Expres...Edureka!
 
Amazon RDS 살펴보기 (김용우) - AWS 웨비나 시리즈
Amazon RDS 살펴보기 (김용우) - AWS 웨비나 시리즈 Amazon RDS 살펴보기 (김용우) - AWS 웨비나 시리즈
Amazon RDS 살펴보기 (김용우) - AWS 웨비나 시리즈 Amazon Web Services Korea
 
How queries work with sharding
How queries work with shardingHow queries work with sharding
How queries work with shardingMongoDB
 
Spring IOC and DAO
Spring IOC and DAOSpring IOC and DAO
Spring IOC and DAOAnushaNaidu
 

What's hot (20)

Explain that explain
Explain that explainExplain that explain
Explain that explain
 
SQL - RDBMS Concepts
SQL - RDBMS ConceptsSQL - RDBMS Concepts
SQL - RDBMS Concepts
 
İleri Seviye T-SQL Programlama - Chapter 04
İleri Seviye T-SQL Programlama - Chapter 04İleri Seviye T-SQL Programlama - Chapter 04
İleri Seviye T-SQL Programlama - Chapter 04
 
Express JS Rest API Tutorial
Express JS Rest API TutorialExpress JS Rest API Tutorial
Express JS Rest API Tutorial
 
SQL JOINS
SQL JOINSSQL JOINS
SQL JOINS
 
Migration From Oracle to PostgreSQL
Migration From Oracle to PostgreSQLMigration From Oracle to PostgreSQL
Migration From Oracle to PostgreSQL
 
Regular Expressions 101 Introduction to Regular Expressions
Regular Expressions 101 Introduction to Regular ExpressionsRegular Expressions 101 Introduction to Regular Expressions
Regular Expressions 101 Introduction to Regular Expressions
 
Introduction to-sql
Introduction to-sqlIntroduction to-sql
Introduction to-sql
 
Tricks every ClickHouse designer should know, by Robert Hodges, Altinity CEO
Tricks every ClickHouse designer should know, by Robert Hodges, Altinity CEOTricks every ClickHouse designer should know, by Robert Hodges, Altinity CEO
Tricks every ClickHouse designer should know, by Robert Hodges, Altinity CEO
 
Sql ppt
Sql pptSql ppt
Sql ppt
 
Node.js Express Tutorial | Node.js Tutorial For Beginners | Node.js + Expres...
Node.js Express Tutorial | Node.js Tutorial For Beginners | Node.js +  Expres...Node.js Express Tutorial | Node.js Tutorial For Beginners | Node.js +  Expres...
Node.js Express Tutorial | Node.js Tutorial For Beginners | Node.js + Expres...
 
MySql slides (ppt)
MySql slides (ppt)MySql slides (ppt)
MySql slides (ppt)
 
MySql:Introduction
MySql:IntroductionMySql:Introduction
MySql:Introduction
 
SQL select clause
SQL select clauseSQL select clause
SQL select clause
 
Amazon RDS 살펴보기 (김용우) - AWS 웨비나 시리즈
Amazon RDS 살펴보기 (김용우) - AWS 웨비나 시리즈 Amazon RDS 살펴보기 (김용우) - AWS 웨비나 시리즈
Amazon RDS 살펴보기 (김용우) - AWS 웨비나 시리즈
 
Postgre sql vs oracle
Postgre sql vs oraclePostgre sql vs oracle
Postgre sql vs oracle
 
PostgreSQL
PostgreSQL PostgreSQL
PostgreSQL
 
PostgreSQL and XML
PostgreSQL and XMLPostgreSQL and XML
PostgreSQL and XML
 
How queries work with sharding
How queries work with shardingHow queries work with sharding
How queries work with sharding
 
Spring IOC and DAO
Spring IOC and DAOSpring IOC and DAO
Spring IOC and DAO
 

Similar to 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
 
BigData_HW3_Boris_Menshikov_15613416.pptx
BigData_HW3_Boris_Menshikov_15613416.pptxBigData_HW3_Boris_Menshikov_15613416.pptx
BigData_HW3_Boris_Menshikov_15613416.pptxMorisMenshen
 
4th Auto Remarketing Forum India 2017
4th Auto Remarketing Forum India 20174th Auto Remarketing Forum India 2017
4th Auto Remarketing Forum India 2017Ilana Kearns
 
Bluebook of Maruti Suzuki
Bluebook of Maruti SuzukiBluebook of Maruti Suzuki
Bluebook of Maruti SuzukiAakash Gupta
 

Similar to 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
 
BigData_HW3_Boris_Menshikov_15613416.pptx
BigData_HW3_Boris_Menshikov_15613416.pptxBigData_HW3_Boris_Menshikov_15613416.pptx
BigData_HW3_Boris_Menshikov_15613416.pptx
 
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
 
Bluebook of Maruti Suzuki
Bluebook of Maruti SuzukiBluebook of Maruti Suzuki
Bluebook of Maruti Suzuki
 

More from 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
 

Recently uploaded

Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Celine George
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxiammrhaywood
 
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfLike-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfMr Bounab Samir
 
What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPCeline George
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxthorishapillay1
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTiammrhaywood
 
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...Nguyen Thanh Tu Collection
 
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfFraming an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfUjwalaBharambe
 
Planning a health career 4th Quarter.pptx
Planning a health career 4th Quarter.pptxPlanning a health career 4th Quarter.pptx
Planning a health career 4th Quarter.pptxLigayaBacuel1
 
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdfAMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdfphamnguyenenglishnb
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentInMediaRes1
 
Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Celine George
 
ROOT CAUSE ANALYSIS PowerPoint Presentation
ROOT CAUSE ANALYSIS PowerPoint PresentationROOT CAUSE ANALYSIS PowerPoint Presentation
ROOT CAUSE ANALYSIS PowerPoint PresentationAadityaSharma884161
 
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxMULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxAnupkumar Sharma
 

Recently uploaded (20)

Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
 
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfLike-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
 
What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERP
 
Rapple "Scholarly Communications and the Sustainable Development Goals"
Rapple "Scholarly Communications and the Sustainable Development Goals"Rapple "Scholarly Communications and the Sustainable Development Goals"
Rapple "Scholarly Communications and the Sustainable Development Goals"
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptx
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
 
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
 
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfFraming an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
 
Planning a health career 4th Quarter.pptx
Planning a health career 4th Quarter.pptxPlanning a health career 4th Quarter.pptx
Planning a health career 4th Quarter.pptx
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdfAMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media Component
 
Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17
 
ROOT CAUSE ANALYSIS PowerPoint Presentation
ROOT CAUSE ANALYSIS PowerPoint PresentationROOT CAUSE ANALYSIS PowerPoint Presentation
ROOT CAUSE ANALYSIS PowerPoint Presentation
 
Raw materials used in Herbal Cosmetics.pptx
Raw materials used in Herbal Cosmetics.pptxRaw materials used in Herbal Cosmetics.pptx
Raw materials used in Herbal Cosmetics.pptx
 
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxMULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 

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.