ソースコード
SELECT
    FOREIGN_ENTER_OUT_AMT_TABLE.PORT_CODE AS '港コード'
    , P.PORT_NAME AS '港名'
    , FOREIGN_ENTER_OUT_AMT_TABLE.ENTER_FOREIGN_TOURIST_AMT AS '入国者数'
    , FOREIGN_ENTER_OUT_AMT_TABLE.OUT_FOREIGN_TOURIST_AMT AS '出国者数'
    , FOREIGN_ENTER_OUT_AMT_TABLE.ENTER_FOREIGN_TOURIST_AMT - FOREIGN_ENTER_OUT_AMT_TABLE.OUT_FOREIGN_TOURIST_AMT AS '差分'
FROM
    (
        SELECT
            SUM_AMT.PORT_CODE
            , MAX(CASE WHEN SUM_AMT.KIND_CODE = '110' THEN SUM_FOREIGN_AMT END) AS ENTER_FOREIGN_TOURIST_AMT
            , MAX(CASE WHEN SUM_AMT.KIND_CODE = '120' THEN SUM_FOREIGN_AMT END) AS OUT_FOREIGN_TOURIST_AMT
        FROM
            (
                SELECT
                    I.PORT_CODE
                    , I.KIND_CODE
                    , SUM(I.AMT) AS SUM_FOREIGN_AMT
                FROM
                    IMMIGRATION AS I
                INNER JOIN
                    GRP AS G
                ON
                    I.GROUP_CODE = G.GROUP_CODE
                WHERE
                    I.KIND_CODE IN ('110', '120')
                    AND
                    G.GROUP_NAME = '外国人' 
                GROUP BY
                    I.PORT_CODE, I.GROUP_CODE, I.KIND_CODE
            ) AS SUM_AMT
        GROUP BY
            SUM_AMT.PORT_CODE
        HAVING
            ENTER_FOREIGN_TOURIST_AMT > OUT_FOREIGN_TOURIST_AMT
    ) AS FOREIGN_ENTER_OUT_AMT_TABLE
INNER JOIN
    PORT AS P
ON
    FOREIGN_ENTER_OUT_AMT_TABLE.PORT_CODE = P.PORT_CODE
ORDER BY
    差分 DESC, P.PORT_CODE DESC
提出情報
提出日時2022/08/14 13:55:25
コンテスト第1回 SQLコンテスト
問題港入出国者分析
受験者yurei
状態 (詳細)AC
(Accepted: 正答)
メモリ使用量80 MB
メッセージ
テストケース(通過数/総数)
2/2
状態
メモリ使用量
データパターン1
AC
80 MB
データパターン2
AC
78 MB