ソースコード
select
  table_in.PORT_CODE as 港コード,
  PORT.PORT_NAME as 港名,
  table_in.AMT as 入国者数,
  table_out.AMT as 出国者数,
  table_in.AMT - table_out.AMT as 差分
from
( 
  select
    i.PORT_CODE as PORT_CODE,
    SUM(i.AMT) as AMT
  from
    IMMIGRATION as i
  join
    GRP as g
  on
    i.GROUP_CODE = g.GROUP_CODE
  where
    g.GROUP_NAME = "外国人" and
    i.KIND_CODE = "110"
  group by
    i.PORT_CODE
) as table_in
join
(
  select
    i.PORT_CODE as PORT_CODE,
    SUM(i.AMT) as AMT
  from
    IMMIGRATION as i
  join
    GRP as g
  on
    i.GROUP_CODE = g.GROUP_CODE
  where
    g.GROUP_NAME = "外国人" and
    i.KIND_CODE = "120"
  group by
    i.PORT_CODE
) as table_out
on 
  table_in.PORT_CODE = table_out.PORT_CODE
join
  PORT
on
  table_in.PORT_CODE = PORT.PORT_CODE
where
  table_in.AMT > table_out.AMT
order by
  差分 desc,
  港コード desc
;
提出情報
提出日時2022/07/20 21:19:36
コンテスト第1回 SQLコンテスト
問題港入出国者分析
受験者vesper
状態 (詳細)AC
(Accepted: 正答)
メモリ使用量102 MB
メッセージ
テストケース(通過数/総数)
2/2
状態
メモリ使用量
データパターン1
AC
101 MB
データパターン2
AC
102 MB