ソースコード
SELECT
     "KIND_CODE_110".PORT_CODE AS "港コード"
    ,PORT.PORT_NAME AS "港名"
    ,"KIND_CODE_110".AMT AS "入国者数"
    ,"KIND_CODE_120".AMT AS "出国者数"
    ,"KIND_CODE_110".AMT - "KIND_CODE_120".AMT AS "差分"
FROM
(
    SELECT
         IMMIGRATION.PORT_CODE
        ,SUM(IMMIGRATION.AMT) AS "AMT"
    FROM
        IMMIGRATION
    LEFT OUTER JOIN
        GRP
    ON
        IMMIGRATION.GROUP_CODE = GRP.GROUP_CODE
    WHERE
            GRP.GROUP_CODE = '120'
        AND IMMIGRATION.KIND_CODE = '110'
    GROUP BY
        IMMIGRATION.PORT_CODE
) AS "KIND_CODE_110"
LEFT OUTER JOIN
(
    SELECT
         IMMIGRATION.PORT_CODE
        ,SUM(IMMIGRATION.AMT) AS "AMT"
    FROM
        IMMIGRATION
    LEFT OUTER JOIN
        GRP
    ON
        IMMIGRATION.GROUP_CODE = GRP.GROUP_CODE
    WHERE
            GRP.GROUP_CODE = '120'
        AND IMMIGRATION.KIND_CODE = '120'
    GROUP BY
        IMMIGRATION.PORT_CODE
) AS "KIND_CODE_120"
ON
    "KIND_CODE_110".PORT_CODE = "KIND_CODE_120".PORT_CODE
LEFT OUTER JOIN
    PORT
ON
    "KIND_CODE_110".PORT_CODE = PORT.PORT_CODE
WHERE
    "KIND_CODE_110".AMT - "KIND_CODE_120".AMT > 0
ORDER BY
     "KIND_CODE_110".AMT - "KIND_CODE_120".AMT DESC
    ,"KIND_CODE_110".PORT_CODE DESC
提出情報
提出日時2022/07/20 20:07:23
コンテスト第1回 SQLコンテスト
問題港入出国者分析
受験者code_abcd
状態 (詳細)AC
(Accepted: 正答)
メモリ使用量103 MB
メッセージ
テストケース(通過数/総数)
2/2
状態
メモリ使用量
データパターン1
AC
103 MB
データパターン2
AC
100 MB