ExamBank Scot · Higher Computing Science question bank · All Higher Computing Science questions

Higher Computing Science 2023 Question 15

10 marks · Aggregate functions and grouping

Design a query to display the output above. Field(s) and Calculation(s) Tables(s) Search Criteria Grouping Sort Order Write an SQL statement to display the title of each race and the average time for that race. The expected output is shown below. title Average Time Clyde Maze 114.27 Factory Frenzy 116.67 Granite Range 103.22 A query was created to display the fastest time in any race. This query was saved as ‘Fastest’ and the output of it is shown below. FastestTime 86.8 Using the ‘Fastest’ query, complete the SQL statement below to display the name of the pilot(s) who achieved this time. SELECT forename,surname The first season was such a success they are running a second season using the same races. The pilot who won the first race of the second season in Aberdeen won the same race in the first season. When the organisers try to add this new record they found the database was not fit for purpose. Explain why this record could not be added to the Entry table. The Caledonian Drone Racing League stores the results of their first season’s competitions in a relational database. Pilots’ times for each race are recorded in seconds. The relational database uses the following three tables. Pilot Race Entry pilotID forename surname raceID title city raceID* pilotID* position raceTime Sample data from the three tables is shown below. Pilot pilotID forename surname P001 Matthew Thomas P002 Ann Wilson P003 Joseph Dow P004 Sam Friar … … … Race raceID title city 1 Granite Range Aberdeen 2 Clyde Maze Glasgow 3 Factory Frenzy Ayr Entry raceID pilotID position raceTime 1 P001 2 92.4 1 P002 3 96.5 1 P003 1 86.8 1 P004 4 98.5 1 P005 5 98.9 … … … … 2 P001 4 120.5 2 P003 2 109.7 2 P002 1 101.5 2 P004 3 115.5 2 P006 5 121.0 … … … … 3 P001 3 109.8 3 P002 2 109.6 3 P003 1 106.9 3 P004 4 145.2 … … … … Pilots win £150 for first place. The league would like to produce a list of the names and total amount of winnings for those pilots that have come in first place. The expected output is shown below. pilotID forename surname Winnings P002 Ann Wilson 150 P003 Joseph Dow 300

Marking scheme

Award 1 mark for each bullet. • Fields with calculation (and alias) • Pilot and Entry tables, where position =1 • Group by pilotID and/or forename, surname Field(s) and Calculation(s) pilotID,forename, surname,COUNT(*) *150 (AS ‘Winnings’) Table(s) Pilot,Entry Search Criteria position = 1 Grouping pilotID, (forename, surname) Sort Order Award 1 mark for each bullet. • SELECT with title and AVG(raceTime) • ALIAS and join for Entry and Race tables • GROUP BY title or raceID SELECT title, AVG(raceTime) AS 'Average Time' FROM Entry,Race WHERE Entry.raceID = Race.raceID GROUP BY title Award 1 mark for each bullet. • FROM includes Pilot, Entry with Pilot.pilotID = Entry.pilotID in WHERE • FROM clause includes ‘Fastest’ • WHERE raceTime =[FastestTime] Do not award bullet point 1 if a GROUP BY clause is included SELECT forename,surname FROM Pilot, Entry, Fastest WHERE raceTime=[FastestTime] AND Pilot.pilotID = Entry.pilotID Sub query also acceptable: SELECT forename, surname FROM Pilot,Entry WHERE racetime = (SELECT MIN(racetime) FROM Entry) and Entry.PilotID = Pilot.pilotID The primary key/raceID and pilotID/compound key would no longer be unique

Previous question: Higher Computing Science 2023 Question 14

Next question: Higher Computing Science 2023 Question 16