SQL - Student
SQL - Student
Databases (SQL)
Unit
Objectives
Silent Starter
1. Make yourself familiar with the example data below, then move on1a
to
the next slide.
Silen
t
Star
t
Silent Starter 1b
2. Answer the query question below. From the previous slide. Copy and
paste the yellow boxes as necessary.
32 Mixed
Silen
t
Star
t
Open SQL – Student PowerPoint in Teams
Complete Slide 5 and 6 Silent Starter 2a
Write an SQL statement that will select Tyre Code, Width, Diameter for
all the Asphalt bikes.
Silen
t
Star
t
Open SQL – Student PowerPoint in Teams
Complete Slide 5 and 6 Silent Starter 2a
Write an SQL statement that will select Tyre Code, Width, Diameter for
all the Asphalt bikes.
Answer here:
SELECT Tyre Code, Width, Diameter
Silen FROM BIKETYRES
t WHERE Terrain = “Asphalt”;
Star
t
Silent Starter 2b
Write an SQL statement that will select Tyre Code, Width, Diameter for
all the mixed bikes, where stock level is less than 10.
Silen
t
Star
t
Silent Starter 2b
Write an SQL statement that will select Tyre Code, Width, Diameter for
all the mixed bikes, where stock level is less than 10.
Answer here:
SELECT Tyre Code, Width, Diameter
Silen FROM BikeTyres
t WHERE Terrain = “Asphalt” AND Stock Level < 10
Star
t
Silent Starter 3a
Write an SQL statement that will count the number of bikes within the
table.
Answer here:
Silen
t
Star
t
Silent Starter 3a
Write an SQL statement that will count the number of bikes within the
table, that have NO Tube and stock level of less than 20.
Answer here:
Silen
t
Star
t
Keywords: Databases
(SQL)
Key Word Definition
SQL Structured Query Language, which is a computer language for
storing, manipulating and retrieving data stored in a relational
database
Field
QUERY – AAcharacteristic of data
method of retrieving something
stored in astored in the
database.
databaseA–specific
SELECT The columns
query which only retrieves data.
Record
ORDER BY –SQL
Allcode,
the which
dataallows
about one
you item
to order inthe
how a database – The
data will be viewed
rows are (either ascending or descending).
a collection of fields.
SUM SQL code – a specific type of query, where a total of a field is
returned.
COUNT SQL code – a specific type of query, where a count of the number
of records is returned.
Keyw
o rds
Querying
fi l te r i n g /
gu a g e for
p u ter l a n d a ta .
o m ti n g
SQL is a c g / editing or dele
mm a r i si n
su
Teac
Expl her
anat
i on
Querying
Teac
Expl her 3. Sorted in asc. order of Last
anat
i on Name
Basic SQL
Teac
Expl her
anat
i on
Querying- SQL
After you have made a query, you
can go to <SQL View>
This will show you the SQL code
for the query.
Presentation
Mode Needed
Teac
Expl her
anat
i on
Querying- SQL
Presentation
Mode Needed
Presentation
Mode Needed
Presentation
Mode Needed
Presentation
Mode Needed
Answer here:
Task
Task 2: Practice
1. From the query below, write out the SQL statement. Query 2.
“Dubai”
Answer here:
Task
Task 3: Practice
1. From the query below, write out the SQL statement. Query 3.
Ascending
“Dubai”
“Abu Dhabi”
Answer here:
Task
Worked Example
From the query below, write out the SQL statement.
Task
Task 5: Practice Query
2.
From the query below, write out the SQL statement.
1. Write a query to get Product list (id, name, unit price) where products cost between $15
and $25 inclusive. Table Name = Products
Answer here:
Select Product Id, Product name, Unit price (£)
From products
Where unit price >= £15 and <= 25;
Task
Task 6: Practice
1. From the sample data below, writeQuery 3.
the query in SQL.
Write a query to display the names (first_name, last_name) where the salary is greater than
15000
Table Name=‘Employees’.
Answer here:
Select first_name , last_name
From employees
Where salary is > 15000
Task
Task 7: Practice Query
4.
1. From the sample data below, write the query in SQL.
Write a query to display the names (first_name, last_name) where the Job ID = ’IT_PROG’ or
‘AD_VP’ AND Salary is greater than 8000. Table Name = ‘Employees’.
Answer here:
Select first_name , last_name
From employees
Where Job_Id = ‘IT_PROG’ or ‘AD_VP’
And salary is > 8000;
Task
Task 8: Practice Query
5.
1. From the sample data below, write the query in SQL.
Write a query to display the names (first_name, last_name) where the manager ID=100
order the query by last name is ascending order. Table Name = ‘Employees’.
Answer here:
Select first_name , last_name
From employees
Where manager Id = 100
Order by last_name;
Task
Task 9: Practice Query
6.
1. From the sample data below, write the query in SQL.
Write a query to find the name Street Address, Postal Code, Country Name. Tables Names =
Location and Country
Answer here:
Select street_adress , postal_code , country_name
From location and country
Task
Task 10: Practice
1. From the sample data below, writeQuery 7.
the query in SQL.
Create a query to show the street address, postal code, state_province and country name for
all country IDs which are ‘US’ or ‘JP’. Table Name = Location and Country.
Answer here:
Select street_adress , postal_code , state_province ,
country_name
FROM LOCATION and COUNTRY
WHERE country_ID = ‘US’ or ‘JP’
Task
Summary Query
Presentation
Mode Needed
Presentation
Mode Needed
e numb er of T EAMS:
To count th
SELECT COUNT(TEAM)
Presentation
Mode Needed
Presentation
Mode Needed
Presentation
Mode Needed
Presentation
c
Mode Needed
A MS w ho have got
TE
cou nt t he number of ames or
To d w on 2 0 g
0 p oin ts o re more an
6
more.
T(TEAM)
SELECT COUN
Teac FROM League
Table
Expl her ND Won>=20;
anat WHERE P ts > =6 0 A
i on
Summary Query
Presentation
Mode Needed
Presentation
Mode Needed
a n y p oin t s were
To add how m
om e ve r y te a m:
won fr
s)
SELECT SUM(Pt
Teac ;
Expl her FROM LeagueTable
anat
i on
Summary Query
Presentation
Mode Needed
Presentation
Mode Needed
Create a query to count how many superheroes there are. TABLE NAME = SuperHeroes.
Answer here:
SELECT count(superhero)
FROM Superheroes;
Task
Task 12.2: Summary
1. From the sample data below, write Query 2.
the query in SQL.
Create a query to count how many males superheroes there are, with Super Strength as their
power 1. TABLE NAME = SuperHeroes.
Answer here:
SELECT COUNT(SUPERHERO)
FROM SuperHeroes
WHERE gender = ‘male’
AND power 1 is = ‘super strength’;
Task
Task 13: Summary Query
3.
1. From the sample data below, write the query in SQL.
Create a query to calculate the total weight of all female superheroes there are. TABLE
NAME = SuperHeroes.
Answer here:
Task
Task 14: Summary Query
4.
1. From the sample data below, write the query in SQL.
Create a query to calculate the total height of all female superheroes there are, with black
hair. TABLE NAME = SuperHeroes.
Answer here:
Task
Task 14: Progress
Check
Create a query to calculate the total height of all female superheroes there are, with black
hair. TABLE NAME = SuperHeroes.
SELECT SUM(HEIGHT)
FROM SuperHeroes
WHERE Gender = ‘Female’ AND Hair=‘Black’;
Feed
ba ck
Task 15: Orders 1
Write a SQL statement to find the total purchase amount of all orders. Table
Name = Orders
Answer here:
Task
Task 16: Orders 3
Write a SQL statement to find to count the number of customers. Table Name
= Customers
Answer here:
Task
Task 17: Orders 3
Write a SQL statement to find to count the number of customers based in New
York.
Table Name = Customers
Answer here:
Task
Summary Query – Group
By
Presentation
Mode Needed
t a tistic s th at a re
m a y w an t to fi nd s
Sometimes you
grouped. e d in e ach
r h eroes a re b a s
ma ny sup e
Lets see how
city.
Teac
Expl her
anat
i on
Summary Query – Group
By
Presentation
Mode Needed
tego ry in th at field.
l add u p each c a
UP B Y it wil
By adding GRO
T CO UN T( S u pe rhero)
SELEC
oes
FROM Superher
.
GROUPBY Lives
Teac
Expl her
anat
i on
Task 18: Orders 2
Write a SQL statement to find the total purchase amount of all orders for
categorised by customer ID. Table Name = Orders
Answer here:
Task
Task 19: Orders 2
Write a SQL statement to find the total purchase amount of all orders for
each salesman Table Name = Orders
Answer here:
Task
Plenary Task 1
Fix the errors in the SQL statement from the table above.
This should show all fields, expect Subject Taken, for all students the that
are doing computer science
Fix the errors in the SQL statement from the table above.
This should show COUNT the number of students taking MATHS.
SELECT COUNT()
FROM Student
WHERE Subject Level = “A”
Plen
a ry
Plenary Task 3
Assess yourself on your logic gates skills so far…
Write an SQL query to display the Nurse ID and family name for all Area B
nurses with a
specialism of 'THEATRE'.
Answer here:
Task
Task: Past Paper 2
The design for a movies databases is as follows:
Write an SQL script to display the title and rating of all movies scheduled to
play on screen number 3.
Answer here:
Task
Task: Past Paper 3
The design for a movies databases is as follows:
Write an SQL script to display the username, firstname, secondname, for all
uploads dated 25/12/2020
Answer here:
Task
Task: Past Paper 4
The design for a movies databases is as follows:
Write an SQL to display the playerID, Purchase Dates and Costs for all orders
over £30, where skill level is 10 or more.
Answer here:
Task
Task: Past Paper 5
The design for a movies databases is as follows:
Write an SQL to display the patient’s name, doctor’s name for all appointments
on 01/03/2020
Answer here:
Task
Task: Past Paper 6
The design for a movies databases is as follows:
Write an SQL script to display the Staff ID of each member of staff who
performed an interview when they visited New Age Toys on 13/10/2016.
Answer here:
Task