ExamBank Scot · Higher Computing Science question bank · All Higher Computing Science questions
13 marks · Aggregate functions and grouping
Design a query to display the customer’s forename, surname and the total amount of hours of lessons booked by each customer during May 2019. The design has been partially completed for you. Field(s) and calculation(s) Table(s) Customer,Booking Search criteria Grouping Sort order The company charges £35 per hour for each lesson booked. Using the sample data provided, write the SQL statement that would produce the following output. Total payments (£) 245 The customer Simon Wenger has moved home. His new address and postcode is 27 Drummer Street, AB33 7QR. Write the SQL statement to make these changes. Design a query to display the forename, surname and the number of lessons booked for each instructor. The instructor who has the most lessons booked should be displayed first. Field(s) and calculation(s) Table(s) Search criteria Grouping Sort order A company offers driving lessons. They have a number of instructors and currently organise their customer bookings as shown in the three database tables below. Instructor instructorID forename surname 1 James Smith 2 Anna Bloggs 3 George Grant 4 Rachel Smith … … Booking bookingID instructorID customerID lessonDuration date time BK0001 4 1 1 01/05/2019 14:00 BK0002 1 2 1 22/05/2019 16:00 BK0003 4 1 2 08/05/2019 14:30 BK0004 2 3 2 12/06/2019 10:00 BK0005 3 2 1 29/05/2019 14:00 … … Customer customerID forename surname address telephone postcode 1 Matthew Thomas 113 Cherry Terrace 07850843527 AB43 4SH 2 Simon Wenger 91 Almo Alley 07892843825 AB33 8UP 3 Nicola Mckay 9 Prairie Crescent 07945043032 AB43 9NZ … …
• forename, surname, SUM(lessonDuration) • selection of date in search • grouping by forename and surname 1 mark for each bullet Date selection may be between, range and use wildcards ( * ?? %) • SUM aggregate function • Calculation of lessonduration * 35 • Alias and Booking table 1 mark for each bullet Example: SELECT SUM(lessonDuration*35) AS 'Total Payments' FROM Booking; Note can be (lessonDuration) * 35 • UPDATE Customer table • SET new address and postcode values • WHERE criteria based on forename and surname OR customer ID 1 mark for each bullet Example: UPDATE Customer SET Address = ’27 Drummer Street’, Postcode = ‘AB33 7QR’ WHERE forename = ‘Simon’ AND surname = ‘Wenger’ OR customerID = 2 • forename, surname and COUNT function on any field • Tables(s): Instructor and Booking • Grouping: forename and surname • Sort Order: Count of field descending 1 mark for each bullet COUNT function can be applied to any field or * Accept ALIAS in the Sort Order
Previous question: Higher Computing Science 2019 Question 16