ソースコード
SELECT
    t1.PF_CODE AS CODE
   ,t2.PF_NAME AS NAME
   ,ROUND(CAST(t1.SUM_DAILY_AMT AS REAL) / CAST(t1.SUM_TOTAL_AMT AS REAL) * 100, 1) AS PERCENTAGE
FROM
   (
      (
         SELECT
             SUM(AMT) AS SUM_DAILY_AMT
            ,PF_CODE
         FROM
            DRINK_HABITS
         WHERE
                CATEGORY_CODE = '120'
            AND GENDER_CODE IN ('2','3')
         GROUP BY
            PF_CODE
      ) daily LEFT JOIN (
         SELECT
             SUM(AMT) AS SUM_TOTAL_AMT
            ,PF_CODE
         FROM
            DRINK_HABITS
         WHERE
                CATEGORY_CODE = '110'
            AND GENDER_CODE IN ('2','3')
         GROUP BY
            PF_CODE
      ) total ON (
         daily.PF_CODE = total.PF_CODE
      )
   ) AS t1 LEFT JOIN PREFECTURE AS t2 ON (
      t1.PF_CODE = t2.PF_CODE
   )
ORDER BY 
    PERCENTAGE DESC
   ,CODE DESC
提出情報
提出日時2022/09/22 08:07:59
コンテスト第2回 SQLコンテスト
問題飲酒率
受験者nezumi
状態 (詳細)AC
(Accepted: 正答)
メモリ使用量89 MB
メッセージ
テストケース(通過数/総数)
2/2
状態
メモリ使用量
データパターン1
AC
86 MB
データパターン2
AC
89 MB