ExamBank Scot · Higher Computing Science question bank · All Higher Computing Science questions
10 marks · Aggregate functions and grouping
Design a query to display the number of orders that the customer with custID 41 made in May 2023. Field(s) and Calculation(s) Tables(s) Search Criteria Grouping Sort Order The takeaway restaurant would like to offer a discount for all customers who order a main dish. Complete the design of a query to display the full name and telephone number of every customer who has ordered a main dish. Field(s) and Calculation(s) Tables(s) Search Criteria course = ‘Main’ Grouping Sort Order The manager wants to increase the price of main dishes that contain chicken by £2.00. Write the SQL statement that would implement this. The restaurant wants a query to calculate the total cost of each order. The expected output is shown below. orderID orderDate Total Value ORD1 15/05/2023 62.91 ORD2 15/05/2023 17.96 ORD3 16/05/2023 51.87 The following SQL statement is executed but the actual output does not match the expected output. SELECT CustOrder.orderID, orderDate, (price * quantity) AS 'Total Value' FROM CustOrder, OrderItem, Dish WHERE CustOrder.orderID = OrderItem.orderID ORDER BY orderID ASC; Identify the three errors in the above SQL statement. Error 1 Error 2 Error 3 A takeaway restaurant is implementing an online ordering system and is using a relational database to store details about the dishes, customers and orders. The restaurant can view order details. Customers are able to place and edit orders. The four tables used in the database are shown below. Customer custID forename surname address telephone postcode 41 Henry Taylor 95 Whitehouse St 01224 931167 AB25 1SL 42 Anna Smith 84 Fraser Ave 01224 474845 AB16 5LL 43 Jane Robin 80 Maxwell St 01224 325715 AB12 5XN … … … … … … CustOrder orderID custID orderDate ORD1 41 15/05/2023 ORD2 42 15/05/2023 ORD3 41 16/05/2023 … … … OrderItem orderID dishID quantity ORD1 DISH01 2 ORD1 DISH05 3 ORD1 DISH04 3 ORD1 DISH06 1 ORD2 DISH02 2 ORD2 DISH04 2 ORD3 DISH03 7 ORD3 DISH04 6 … … … Dish dishID description course price DISH01 Pepper and egg sushi Starter 6.99 DISH02 Poppy and rosemary salad Main 4.99 DISH03 Ice cream Dessert 3.99 DISH04 Cappuccino Drink 3.99 DISH05 Chicken fajita Main 8.99 DISH06 One pan chicken Main 9.99 DISH07 Chilli chicken wings Starter 4.99 … … … …
Award 1 mark for each bullet. • COUNT(any field or *) • WHERE condition custID =41 and date in May 23 Field(s) and Calculation(s) COUNT(*) Table(s) CustOrder Search Criteria custID = 41 AND orderDate LIKE “%/05/2023” Grouping Sort Order Do not penalise additional entries in Field(s) and Calculation(s). In design accept other expressions eg = for LIKE BETWEEN for dates SQL allows: custID = 41 AND orderDate LIKE “%/05/2023” custID = 41 AND orderDate LIKE “ _ _/05/2023” Access allows: custID = 41 AND orderDate LIKE “*/05/2023” custID = 41 AND orderDate LIKE “??/05/2023” Award 1 mark for each bullet. • Correct three fields • All four tables Field(s) and Calculation(s) forename, surname, telephone Table(s) Customer, CustOrder, OrderItem, Dish Search Criteria course = ‘Main’ Grouping (CustID) Sort Order Award 1 mark for each bullet. • UPDATE Dish • SET price = price + 2 • WHERE course = ‘Main’ AND description LIKE ‘%Chicken%’ Award 0 marks for first bullet if SQL clauses are in wrong order Access: Accept * for wildcard Award 1 mark for each bullet. • Missing SUM/TOTAL around calculation • Missing join between OrderItem and Dish tables • Missing GROUP BY orderID, (orderDate)
Previous question: Higher Computing Science 2023 Question 13