ソースコード
SELECT
    PORT_CODE AS "港コード",
        PORT_NAME AS "港名",
        IN_AMT AS "入国者数",
        OUT_AMT AS "出国者数",
        diff AS "差分"
FROM
(
    SELECT
        PORT_CODE,
        PORT_NAME,
        SUM(IN_AMT) AS IN_AMT,
        SUM(OUT_AMT) AS OUT_AMT,
        SUM(IN_AMT) - SUM(OUT_AMT) AS diff
    FROM(
        SELECT
            imm.PORT_CODE AS PORT_CODE,
            PORT_NAME,
            CASE WHEN KIND_CODE = "110" THEN AMT ELSE NULL END AS IN_AMT,
            CASE WHEN KIND_CODE = "120" THEN AMT ELSE NULL END AS OUT_AMT
        FROM
            IMMIGRATION AS imm
        INNER JOIN PORT
            ON imm.PORT_CODE = PORT.PORT_CODE
        INNER JOIN GRP
            ON imm.GROUP_CODE = GRP.GROUP_CODE
        WHERE TRUE
            AND KIND_CODE IN ("110", "120")
            AND imm.GROUP_CODE = "120"
    )
    GROUP BY
        PORT_CODE
)
WHERE
    diff  > 0
ORDER BY
    diff DESC,
    PORT_CODE DESC
提出情報
提出日時2023/02/24 12:16:51
コンテスト第1回 SQLコンテスト
問題港入出国者分析
受験者alfabravocharlie224
状態 (詳細)AC
(Accepted: 正答)
メモリ使用量81 MB
メッセージ
テストケース(通過数/総数)
2/2
状態
メモリ使用量
データパターン1
AC
81 MB
データパターン2
AC
78 MB