Igcse Compsci 2ed TR Worksheet 9.2
Igcse Compsci 2ed TR Worksheet 9.2
Name Date
9.2 SQL
These questions use the following database table, APPOINTMENT.
Getting started
Match the SQL queries to their output.
SELECT CustomerID 56
FROM APPOINTMENT 58
WHERE Attended? = Yes 57
59
60
Cambridge IGCSE™ & O Level Computer Science – Ellis © Cambridge University Press 2021 1
CAMBRIDGE IGCSE™ & O LEVEL COMPUTER SCIENCE: WORKSHEET 9.2
SELECT AppointmentID 57
FROM APPOINTMENT 56
WHERE Date = 10/10/2020
ORDER BY Time Desc
SELECT SUM(Fee) 2
FROM APPOINTMENT
WHERE Attended? = No
SELECT SUM(Fee) 5
FROM APPOINTMENT
WHERE Date = 10/10/2020
Practice
Identify the output from the following SQL scripts:
1 SELECT Appointment ID, CustomerID
FROM APPOINTMENT
WHERE Date = 11/10/2020 AND Attended = No
2 SELECT Date, Time
FROM APPOINTMENT
WHERE Fee < 200
ORDER BY Fee DESC
Cambridge IGCSE™ & O Level Computer Science – Ellis © Cambridge University Press 2021 2
CAMBRIDGE IGCSE™ & O LEVEL COMPUTER SCIENCE: WORKSHEET 9.2
Challenge
Complete the following SQL scripts.
1 Return the Customer IDs of all customers attended an appointment on the 10/10/2020.
CustomerID
APPOINTMENT
Date = 10/10/2020
SELECT
FROM
3 Return the Date and Time of all appointments on the 11/10/2020 where the fee is less
than 100.00
SELECT ,
FROM APPOINTMENT
Fee 100
Cambridge IGCSE™ & O Level Computer Science – Ellis © Cambridge University Press 2021 3
CAMBRIDGE IGCSE™ & O LEVEL COMPUTER SCIENCE: WORKSHEET 9.2
4 Return the Fee of all customers who attended appointments on the 10/10/2020 in
descending order of Time.
SELECT Fee
FROM APPOINTMENT
WHERE
Time
SELECT ( )
FROM APPOINTMENT
SELECT (AppointmentID)
FROM APPOINTMENT
Cambridge IGCSE™ & O Level Computer Science – Ellis © Cambridge University Press 2021 4