ソースコード
WITH t1 AS (SELECT PF_CODE, TOTAL_VALUE FROM CONVENIENCE WHERE SURVEY_YEAR = 2019 AND KIND_CODE = '100')
   , t2 AS (SELECT PF_CODE, TOTAL_VALUE te FROM CONVENIENCE WHERE SURVEY_YEAR = 2019 AND KIND_CODE = '150')
   , t3 AS (SELECT t1.TOTAL_VALUE sal, t2.te, NTILE(10) OVER ( ORDER BY t1.TOTAL_VALUE DESC, t2.te, t1.PF_CODE) no
            FROM t1
                 LEFT JOIN t2 ON t1.PF_CODE = t2.PF_CODE)
SELECT t.no as NO
     , MAX(TTL_SAL) TTL_SAL
     , MAX(PER_SAL) PER_SAL
     , ROUND(CAST(SUM(tmp.sal) AS real) / MAX(tot) * 100, 1) CUM_SAL
     , MAX(AVG_SAL) AVG_SAL
FROM (SELECT t3.no
           , SUM(t3.sal) TTL_SAL
           , ROUND(CAST(SUM(t3.sal) AS real) / MAX(tot.val) * 100, 1) PER_SAL
           , FLOOR(CAST(SUM(t3.sal) AS real) / SUM(t3.te)) AVG_SAL
           , MAX(tot.val) tot
      FROM t3
         , (SELECT SUM(sal) val FROM t3) tot
      GROUP BY t3.no
      ORDER BY t3.no) t
     LEFT JOIN t3 AS tmp ON t.no >= tmp.no
GROUP BY t.no
提出情報
提出日時2024/06/16 03:15:34
コンテスト第9回 SQLコンテスト
問題販売額分析
受験者pp1mqa6hkm
状態 (詳細)AC
(Accepted: 正答)
メモリ使用量85 MB
メッセージ
テストケース(通過数/総数)
3/3
状態
メモリ使用量
データパターン1
AC
85 MB
データパターン2
AC
84 MB
データパターン3
AC
84 MB