Diagnosing inflated totals across two detail tables

An online retailer stores orders, ordered quantities and payments in three tables. The tables below contain all records relevant to this report. Each line_id and each payment_id is unique. Payments apply to whole orders rather than individual order lines, and all monetary amounts are in Canadian dollars (CAD).


Orders


order_id

910

911


OrderLines


line_id

order_id

units

41

910

3

42

910

5

43

911

4


Payments


payment_id

order_id

payment_cad

71

910

30

72

910

50

73

910

20

74

911

25

75

911

35


Orders connects separately to OrderLines and Payments through order_id.


An analyst runs:


SQL
SELECT SUM(l.units) AS reported_units,
       SUM(p.payment_cad) AS reported_payments
FROM Orders AS o
INNER JOIN OrderLines AS l
    ON o.order_id = l.order_id
INNER JOIN Payments AS p
    ON o.order_id = p.order_id;


Find the reported units and reported payments. Also find the excess units and excess payments, defined as each reported total minus the corresponding total obtained by counting every source detail record once. Enter all four answers as exact integers; enter monetary answers in CAD without a currency symbol.

Your answers

Create a free account to get started

Unlock full course notes by signing up

  • Video lessons taught by top educators
  • Practice questions with guided solutions
  • Written review notes for reference
  • Expert answers anytime from course tutors

More Multiple Table Queries Questions: