ExamBank Scot · Higher Computing Science question bank · All Higher Computing Science questions
3 marks · Aggregate functions and grouping
A swimming club uses a database to store details of swimmers and their times in a 50 metres swim. A sample of the data stored in the Swimmer table is shown below. Swimmer swimmerNo swimmer squad time 001 M Marston Dolphins1A 30.25 002 S Cochrane Dolphins2A 25.75 003 L Richards Dolphins1B 30.23 004 F Qazi Dolphins2A 35.45 005 R Mirza Dolphins1A 28.15 006 J Smith Sharks1A 29.35 007 L Pascal Sharks2A 32.25 008 F McDonald Sharks1B 31.45 009 T Madison Sharks2B 36.54 010 M Johnston Sharks1B 39.15 011 M Davidson Sharks1A 29.45 012 Z Habib Dolphins1A 25.45 013 K Patel Sharks1B 33.76 … … … … The head coach would like to produce a report displaying the slowest and fastest times from any of the squads with a ‘1’ in their name, as shown below. squad Slowest Time Fastest Time Dolphins1A 30.25 25.45 Dolphins1B 30.23 30.23 Sharks1A 29.45 29.35 Sharks1B 39.15 31.45 The following SQL statement is executed. SELECT squad, MIN(time) AS [Slowest Time], MAX(time) AS [Fastest Time] FROM Swimmer WHERE squad LIKE "1" When tested, the actual output did not match the expected output. Identify the three errors in the above SQL statement. Error 1 Error 2 Error 3
• MIN & MAX functions are wrong way round OR ALIAS assigned to wrong function • no wildcard operator both sides of 1 • no GROUP BY squad Accept wildcard (* or %) eg WHERE squad LIKE "%1%" Wildcard operator on the right can be for a single character.