ITPEC IP October 2018 Question 27

Topic: DatabasesAlso asked in October 2020

The “Sales Details” table and the “Products” table are managed in a relational database. What is the total number of notebooks sold?

Sales Details

VouchernumberProduct_codeNumber_sold
H001S00120
H001S00340
H002S00260
H002S00380

Products

Product_codeProduct_name
S001Pencil
S002Eraser
S003Notebook

Explanation

120 — look up the product code of Notebook in Products, then add Number_sold over every Sales Details row with that code.

  • •Products: Notebook has Product_code S003
  • •Sales Details rows with S003: voucher H001 sold 40, voucher H002 sold 80
  • •Total: 40 + 80 = 120

This is a join of the two tables on Product_code, keeping the rows whose Product_name is Notebook, then SUM(Number_sold).

Answer (c)

Why not others:

  • •(a) 40 — only voucher H001's notebook row; H002 also sold notebooks
  • •(b) 80 — only voucher H002's notebook row
  • •(d) 200 — adds every row, 20 + 40 + 60 + 80, pencils and erasers included

Key rule: A code in one table means nothing until it is looked up in the table it refers to; filter on it, then aggregate every matching row, not just the first.

Databases · AI-written, may contain errors

This question comes from an official ITPEC past paper. ITPEC Practice is an independent study tool and is not affiliated with ITPEC. See the official IP past-paper collection or Report an issue.