2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

電脳少女プログラミング2088 巨大コーポの最上階 を解いてみた

Last updated at Posted at 2025-02-11

paiaの電脳少女 SQL問題を解いてみました。
以下、リンクになります。

問題概要

画像のようなテーブルが与えられます。
ここから memory.id, memory.talk, person.name, battle.created_at を取得してください。
ただし、以下の条件が必要です。

  • person (人物) のうち重要度が 5 の人物の person.deleted_at と同じ battle (戦闘) の battle.created_at (戦闘.作成日)

スクリーンショット (1).png

解法

まずは必要なテーブルを確認。
今回は以下の 4 つ。

  • memory, log, battle, person

結合に関しては画像を見れば、つながりが分かるため素直に結合。

条件は 「person の重要度が 5 かつ、person.deleted_at と battle (戦闘) battle.created_at が同じ」なので以下のように書けます。

person.importance = 5
AND person.deleted_at = battle.created_at

これを実装すれば解くことができました。

解答例

SELECT
    memory.id,
    memory.talk,
    person.name,
    battle.created_at
FROM
    memory
INNER JOIN
    log
ON
    memory.id = log.memory_id
INNER JOIN
    battle
ON
    log.person_id = battle.person_id
INNER JOIN
    person
ON
    battle.person_id = person.id
WHERE
    person.importance = 5
    AND person.deleted_at = battle.created_at
;

余談

並び替えの指定がありませんでしたが、何が想定なのでしょうかね。
私にはわかりません😑

2
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?