ソースコード
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 no, SUM(sal) sal, SUM(te) te
            FROM (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) t
            GROUP BY t.no)
   , t4 AS (SELECT t3.no, SUM(tmp.sal) s
            FROM t3
                 LEFT JOIN t3 AS tmp ON t3.no >= tmp.no
            GROUP BY t3.no)
SELECT t3.no NO
     , t3.sal TTL_SAL
     , ROUND(CAST(t3.sal AS real) / tot.val * 100, 1) PER_SAL
     , ROUND(CAST(t4.s AS real) / tot.val * 100, 1) CUM_SAL
     , FLOOR(CAST(t3.sal AS real) / t3.te) AVG_SAL
FROM t3
     LEFT JOIN t4 ON t3.no = t4.no
   , (SELECT SUM(sal) val FROM t3) tot
GROUP BY t3.no
ORDER BY t3.no
;
提出情報
提出日時2024/06/16 03:27:08
コンテスト第9回 SQLコンテスト
問題販売額分析
受験者pp1mqa6hkm
状態 (詳細)AC
(Accepted: 正答)
メモリ使用量84 MB
メッセージ
テストケース(通過数/総数)
3/3
状態
メモリ使用量
データパターン1
AC
84 MB
データパターン2
AC
84 MB
データパターン3
AC
84 MB