ソースコード
select
    IMM2.PORT_CODE as 港コード
,   IMM2.PORT_NAME as 港名
,   sum(IMM2.ENTRY) as 入国者数
,   sum(IMM2.DEPART) as 出国者数
,   sum(IMM2.DIFF) as 差分
from
(
    select
        IMM.PORT_CODE as PORT_CODE
    ,   PORT.PORT_NAME as PORT_NAME
    ,   IMM.AMT as ENTRY
    ,   0 as DEPART
    ,   IMM.AMT as DIFF
    from
        IMMIGRATION as IMM
    ,   PORT
    where
        IMM.PORT_CODE = PORT.PORT_CODE
    and IMM.GROUP_CODE = '120' --外国人
    and IMM.KIND_CODE = '110' --入国者

    union

    select
        IMM.PORT_CODE as PORT_CODE
    ,   PORT.PORT_NAME as PORT_NAME
    ,   0 as ENTRY
    ,   IMM.AMT as DEPART
    ,   -IMM.AMT as DIFF
    from
        IMMIGRATION as IMM
    ,   PORT
    where
        IMM.PORT_CODE = PORT.PORT_CODE
    and IMM.GROUP_CODE = '120' --外国人
    and IMM.KIND_CODE = '120' --出国者
) as IMM2
group by
    IMM2.PORT_CODE
,   IMM2.PORT_NAME
having
    sum(IMM2.DIFF) > 0
order by
    sum(IMM2.DIFF) DESC
,   IMM2.PORT_CODE DESC
提出情報
提出日時2022/07/22 01:59:35
コンテスト第1回 SQLコンテスト
問題港入出国者分析
受験者marocas
状態 (詳細)AC
(Accepted: 正答)
メモリ使用量79 MB
メッセージ
テストケース(通過数/総数)
2/2
状態
メモリ使用量
データパターン1
AC
79 MB
データパターン2
AC
76 MB