Skip to content

平成31年度 春期 ITパスポート試験 問78

This question's explanation and your answers so far.

問78
頻出度★★☆

関係データベースの“社員”表と“部署”表がある。“社員”表と“部署”表を結合し,社員の住所と所属する部署の所在地が異なる社員を抽出する。抽出される社員は何人か。 社員

社員ID氏名部署コード住所
H001伊藤 花子G02神奈川県
H002高橋 四郎G01神奈川県
H003鈴木 一郎G03三重県
H004田中 春子G04大阪府
H005渡辺 二郎G03愛知県
H006佐藤 三郎G02神奈川県

部署

部署コード部署名所在地
G01総務部東京都
G02営業部神奈川県
G03製造部愛知県
G04開発部大阪府
出典 平成31年度 春期 ITパスポート試験 問78
解説

問 78

  • Incorrectア

    «1 person». The employees whose residence differs from the location are H002 and H003, i.e. 2 people; counting only 1 falls short — this is an undercount.

  • イ

    正解 Join the «Employee» and «Department» tables on the department code, and compare each employee's «Residence» with the «Location» of the department they belong to. Only the following 2 employees have a residence that differs from the location. H002 Shiro Takahashi: department G01 (General Affairs Dept.) is located in Tokyo, but his residence is Kanagawa Pref., so they differ. H003 Ichiro Suzuki: department G03 (Manufacturing Dept.) is located in Aichi Pref., but his residence is Mie Pref., so they differ. The remaining 4 all match (H001 = Kanagawa = Kanagawa, H004 = Osaka = Osaka, H005 = Aichi = Aichi, H006 = Kanagawa = Kanagawa). Therefore 2 employees are extracted, and the correct answer is «イ».

  • Incorrectウ

    «3 people». Only H002 and H003 differ, i.e. 2 people. For example H006 (residence Kanagawa Pref.; department G02 Sales Dept. located in Kanagawa Pref.) matches, so H006 is not extracted and the total never reaches 3.

  • Incorrectエ

    «4 people». This overcounts by also including the employees whose location matches their residence (H001, H004, H005, H006). In reality only 2 differ.

ここがポイント
  • Join: link the two tables using the shared column (department code) as the key, so that each employee's department location can be referenced.
  • Evaluating the extraction condition: from each joined row, select only the rows where «residence ≠ location» (selection), then count how many there are.
用語

Your answers