ソースコード
select
    "港コード",
    "港名",
    "入国者数",
    "出国者数",
    "入国者数" - "出国者数" as "差分"
from
    (
        select
            PORT_CODE as "港コード",
            PORT_NAME as "港名",
            max(
                case
                    when KIND_CODE == "110" then AMT
                    else 0
                end
            ) as "入国者数",
            max(
                case
                    when KIND_CODE == "120" then AMT
                    else 0
                end
            ) as "出国者数"
        from
            (
                select
                    PORT_CODE,
                    PORT_NAME,
                    KIND_CODE,
                    sum(AMT) as AMT
                from
                    (
                        select
                            I.PORT_CODE as PORT_CODE,
                            P.PORT_NAME as PORT_NAME,
                            I.GROUP_CODE as GROUP_CODE,
                            I.KIND_CODE as KIND_CODE,
                            I.AMT as AMT
                        from
                            GRP as G,
                            IMMIGRATION as I,
                            PORT as P
                        where
                            I.PORT_CODE == P.PORT_CODE
                            and G.GROUP_CODE == I.GROUP_CODE
                            and I.KIND_CODE in ("110", "120")
                            and G.GROUP_NAME == "外国人"
                    )
                group by
                    PORT_CODE,
                    PORT_NAME,
                    KIND_CODE
            )
        group by
            PORT_CODE,
            PORT_NAME
    )
where
    "入国者数" > "出国者数"
order by
    "差分" desc,
    "港コード" desc
提出情報
提出日時2024/02/16 20:52:30
コンテスト第1回 SQLコンテスト
問題港入出国者分析
受験者shogo314
状態 (詳細)AC
(Accepted: 正答)
メモリ使用量89 MB
メッセージ
テストケース(通過数/総数)
2/2
状態
メモリ使用量
データパターン1
AC
89 MB
データパターン2
AC
84 MB