Skip to content

平成25年度 春期 ITパスポート試験 問61

This question's explanation and your answers so far.

問61
頻出度★★☆

関係データベースの“売上”表と“顧客”表を顧客コードで結合し,顧客コードでグループ化して顧客ごとの売上金額の合計を求め,売上金額の合計を降順に整列した。得られた結果の先頭レコードの顧客名はどれか。 売上

伝票番号顧客コード売上金額(万円)
H001K0140
H002K0280
H003K03120
H004K0470
H005K0120
H006K0250

顧客

顧客コード顧客名
K01井上花子
K02佐藤太郎
K03鈴木三郎
K04田中梅子
出典 平成25年度 春期 ITパスポート試験 問61
解説

問 61

  • Incorrectア

    The total for Inoue Hanako (K01) is 40 + 20 = 60, the smallest of the four, so in descending order she comes last (fourth). She has two slips, so the number of slips is larger, but her total amount is the lowest.

  • イ

    正解 Calculate by following the stated steps. First, join the “Sales” table and the “Customer” table on the customer code, group by customer code, and total the sales amounts. K01 (Inoue Hanako) is 40 + 20 = 60, K02 (Sato Taro) is 80 + 50 = 130, K03 (Suzuki Saburo) is 120, and K04 (Tanaka Umeko) is 70 (all in units of 10,000 yen). Sorting these in descending order (largest first) by total sales amount gives 130 → 120 → 70 → 60, that is, Sato Taro → Suzuki Saburo → Tanaka Umeko → Inoue Hanako. Therefore the customer name in the first record is Sato Taro, and the correct answer is “イ”. The key point is to compare the “total amount for each customer”, not the highest amount of a single slip.

  • Incorrectウ

    The 120 of Suzuki Saburo (K03) is indeed the largest amount for a single slip, but as a total it does not reach Sato Taro's 130, so he is only second. Mixing up the “highest amount on a single slip” with the “total amount for each customer” is the typical trap in this question.

  • Incorrectエ

    Tanaka Umeko (K04) has only one sale, H004 for 70, so her total of 70 ranks third. She does not become the first record in the descending order.

ここがポイント
  • Understand the meaning of the sequence of operations: join + grouping (GROUP BY) + aggregation (SUM) + sorting (ORDER BY, descending). The key is the order: match the two tables using the join key (here, the customer code), compute the total for each group, and only then sort.
  • The “first record” of a result sorted in descending order is the row with the largest aggregated value. Note that what is compared is the totals after grouping, not the maximum value among the individual line items (slips).
用語

Your answers