ExamBank Scot · Higher Computing Science question bank · All Higher Computing Science questions
9 marks · Aggregate functions and grouping
Design a query to display the full name of each photographer and the number of appointments that they have in July 2025. Field(s) and calculation(s) Table(s) Search criteria Grouping Sort order The photography company is increasing the cost by £20 for appointments where their invoice date was before 31 March 2025 and remains unpaid. Write the SQL statement that would change the total cost for these appointments. The company would like to display a list showing the highest cost that has been invoiced for each photographer. The expected output is shown below. fName sName Highest cost Fernami Hardie 100.00 Alisha Hussain 650.90 The following SQL statement is not fit for purpose. SELECT fName, sName, MAX(cost) AS [Highest cost] FROM Invoice, Photographer WHERE Invoice.appID = Appointment.appID ORDER BY MAX(cost) ASC; Describe three errors in the above SQL statement. Error 1 Error 2 Error 3 A photography company uses a database to store and manage data about customers, appointments, photographers and invoices. Sample data from the database is shown below. Customer custID firstname surname phoneNo postcode C001 Liam Miller 05878834723 G68 3JN C002 Max Wilson 05318748333 EH1 1DJ C003 Arran Jones 05773834934 DD1 8JR C004 Anabiah Awan 05934429391 FK8 4RW C005 Olivia Waugh 05417723837 G64 3WP … … … … … Appointment appID custID staffID appDate time location notes APP1 C001 P1 14/12/2024 14:00 Victoria Park Photos of child APP2 C002 P4 02/02/2025 19:30 Castle Engagement APP3 C003 P5 15/02/2025 09:00 Science Museum Work pictures APP4 C001 P1 10/03/2025 12:00 Central Park Family portrait APP5 C004 P4 15/03/2025 14:00 Cathedral Wedding photos … … … … … … … Photographer staffID fName sName email speciality P1 Heidi Colvin colvin@sqmail.com Family P2 Sheikh Momin momin@sqmail.com Fashion P3 Jayden Nelson jnels@sqmail.com Portrait P4 Alisha Hussain alishah@sqmail.com Wedding P5 Fernami Hardie hardie@sqmail.com Event … … … … … Invoice invoiceID appID invoiceDate cost status INV001 APP1 18/12/2024 156.45 Paid INV002 APP2 10/02/2025 250.00 Paid INV003 APP3 20/02/2025 100.00 Unpaid INV004 APP4 16/03/2025 95.00 Paid INV005 APP5 20/04/2025 650.90 Unpaid … … … … …
• COUNT(any field or *) • Field names, tables and criteria • GROUP BY fName,sName/staffID Field(s) and Calculation(s) fName,sName, COUNT (*) Tables(s) Photographer, Appointment Search Criteria appDate like %/07/2025 Grouping fName,sName Sort Order Grouping can also be by staffID. Accept * or ?? or__ for wildcard operator. Date criteria can be specified through wildcards or range (1/7/25-31/7/25). • UPDATE Invoice • SET cost = cost + 20 • WHERE Status = "Unpaid" and invoiceDate < 31/03/2025 Award 0 marks for first bullet if SQL clauses are in wrong order. UPDATE Invoice SET cost = cost + 20 WHERE Status = "Unpaid" and invoiceDate < ‘31/03/2025’ • missing Appointment table • missing join between Appointment and Photographer table • missing GROUP BY fName, sName (or staffID) is needed
Previous question: Higher Computing Science 2025 Question 11