ソースコード
SELECT DISTINCT
 P.PF_CODE AS CODE
,P.PF_NAME AS NAME
,ROUND( 
        CAST(TARGET_TABLE1.NUM1 AS REAL) /
        CAST( TARGET_TABLE2.NUM2 AS REAL )
        * 100
        , 1
    ) AS PERCENTAGE
FROM
  DRINK_HABITS AS DH
  LEFT OUTER JOIN
    PREFECTURE  AS P
  ON
    DH.PF_CODE  = P.PF_CODE
  LEFT OUTER JOIN 
  (
    SELECT
    DH1.PF_CODE AS PF_CODE1
    ,DH1.CATEGORY_CODE AS CATEGORY_CODE1
    ,SUM(DH1.AMT) AS NUM1
    FROM
      DRINK_HABITS AS DH1
    WHERE
      DH1.GENDER_CODE IN ('2','3')
    AND  DH1.CATEGORY_CODE = '110'
    GROUP BY 
      PF_CODE1
      ,CATEGORY_CODE1
    ) AS TARGET_TABLE1
  ON
    TARGET_TABLE1.PF_CODE1 = P.PF_CODE
  LEFT OUTER JOIN 
  (
    SELECT
    DH2.PF_CODE AS PF_CODE2
    ,DH2.CATEGORY_CODE AS CATEGORY_CODE2
    ,SUM(DH2.AMT) AS NUM2
    FROM
      DRINK_HABITS AS DH2
    WHERE
      DH2.GENDER_CODE IN ('2','3')
    AND  DH2.CATEGORY_CODE = '120'
    GROUP BY 
      PF_CODE2
      ,CATEGORY_CODE2
    ) AS TARGET_TABLE2
  ON
    TARGET_TABLE2.PF_CODE2 = P.PF_CODE
ORDER BY
 PERCENTAGE DESC
,CODE DESC
提出情報
提出日時2022/09/22 11:17:33
コンテスト第2回 SQLコンテスト
問題飲酒率
受験者yusayusayu
状態 (詳細)WA
(Wrong Answer: 誤答)
メモリ使用量107 MB
メッセージ
テストケース(通過数/総数)
0/2
状態
メモリ使用量
データパターン1
WA
89 MB
データパターン2
WA
107 MB