関係データベースの“売上”表と“顧客”表を顧客コードで結合し,顧客コードでグループ化して顧客ごとの売上金額の合計を求め,売上金額の合計を降順に整列した。得られた結果の先頭レコードの顧客名はどれか。 売上
| 伝票番号 | 顧客コード | 売上金額(万円) |
|---|---|---|
| H001 | K01 | 40 |
| H002 | K02 | 80 |
| H003 | K03 | 120 |
| H004 | K04 | 70 |
| H005 | K01 | 20 |
| H006 | K02 | 50 |
顧客
| 顧客コード | 顧客名 |
|---|---|
| K01 | 井上花子 |
| K02 | 佐藤太郎 |
| K03 | 鈴木三郎 |
| K04 | 田中梅子 |
This question's explanation and your answers so far.
関係データベースの“売上”表と“顧客”表を顧客コードで結合し,顧客コードでグループ化して顧客ごとの売上金額の合計を求め,売上金額の合計を降順に整列した。得られた結果の先頭レコードの顧客名はどれか。 売上
| 伝票番号 | 顧客コード | 売上金額(万円) |
|---|---|---|
| H001 | K01 | 40 |
| H002 | K02 | 80 |
| H003 | K03 | 120 |
| H004 | K04 | 70 |
| H005 | K01 | 20 |
| H006 | K02 | 50 |
顧客
| 顧客コード | 顧客名 |
|---|---|
| K01 | 井上花子 |
| K02 | 佐藤太郎 |
| K03 | 鈴木三郎 |
| K04 | 田中梅子 |
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.
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.
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.