ソースコード
WITH total AS 
(
 SELECT
  a.PF_CODE AS CODE,
  b.PF_NAME AS NAME,
  SUM(CAST(a.AMT AS FLOAT)) AS AMT
 FROM
  DRINK_HABITS AS a
 LEFT JOIN
  PREFECTURE AS b
 USING
  (PF_CODE)
 WHERE
  CATEGORY_CODE = '110'
 AND
  GENDER_CODE <> '1'
 GROUP BY
  CODE,NAME
),
total_drink AS 
(
 SELECT
  a.PF_CODE AS CODE,
  b.PF_NAME AS NAME,
  SUM(CAST(a.AMT AS FLOAT)) AS AMT
 FROM
  DRINK_HABITS AS a
 LEFT JOIN
  PREFECTURE AS b
 USING
  (PF_CODE)
 WHERE
  CATEGORY_CODE = '120'
 AND
  GENDER_CODE <> '1'
 GROUP BY
  CODE,NAME
)
SELECT
 a.CODE AS CODE,
 a.NAME AS NAME,
 ROUND(100*(b.AMT/a.AMT),1) AS PERCENTAGE
FROM
 total AS a
LEFT JOIN
 total_drink AS b
USING
 (CODE)
ORDER BY
 PERCENTAGE DESC,CODE DESC
提出情報
提出日時2024/02/03 22:34:08
コンテスト第2回 SQLコンテスト
問題飲酒率
受験者romi0416
状態 (詳細)AC
(Accepted: 正答)
メモリ使用量89 MB
メッセージ
テストケース(通過数/総数)
2/2
状態
メモリ使用量
データパターン1
AC
89 MB
データパターン2
AC
85 MB