------------------------------------------------------------------ -- Copyright(c) 2016 pakkin. All Rights Reserved. -- [改訂履歴] -- 2016.07.03 作成 ------------------------------------------------------------------ SELECT V_1.GROUP_ID , V_1.MEISAI_ID , DENSE_RANK() OVER(ORDER BY V_1.GROUP_ID) AS GROUP_NO , ROW_NUMBER() OVER(PARTITION BY V_1.GROUP_ID ORDER BY V_1.MEISAI_ID) AS MEISAI_NO , LISTAGG(V_1.VALUE, ',') WITHIN GROUP(ORDER BY V_1.VALUE ASC) AS VALUE_LIST , SUM(SUM(V_1.VALUE)) OVER(PARTITION BY V_1.GROUP_ID) AS GROUP_SUMMARY , SUM(SUM(V_1.VALUE)) OVER() AS TOTAL_SUMMARY FROM ( SELECT 'A01' AS GROUP_ID, '001' AS MEISAI_ID, 1 AS VALUE FROM DUAL UNION ALL SELECT 'A01', '002', 2 FROM DUAL UNION ALL SELECT 'A01', '003', 3 FROM DUAL UNION ALL SELECT 'A01', '003', 4 FROM DUAL UNION ALL SELECT 'A02', '001', 5 FROM DUAL UNION ALL SELECT 'A02', '002', 6 FROM DUAL UNION ALL SELECT 'A02', '003', 7 FROM DUAL UNION ALL SELECT 'A03', '001', 8 FROM DUAL UNION ALL SELECT 'A03', '001', 9 FROM DUAL UNION ALL SELECT 'A03', '001', 10 FROM DUAL ) V_1 GROUP BY V_1.GROUP_ID , V_1.MEISAI_ID ORDER BY V_1.GROUP_ID , V_1.MEISAI_ID ;
GROUP_ID MEISAI_ID GROUP_NO MEISAI_NO VALUE_LIST GROUP_SUMMARY TOTAL_SUMMARY -------- --------- -------- --------- ---------- ------------- ------------- A01 001 1 1 1 10 55 A01 002 1 2 2 10 55 A01 003 1 3 3,4 10 55 A02 001 2 1 5 18 55 A02 002 2 2 6 18 55 A02 003 2 3 7 18 55 A03 001 3 1 8,9,10 27 55
Copyright(c) 2014-2022 pakkin. All Rights Reserved.