使用SUM(...) OVER (ORDER BY ...)
分析関数:
SQL Fiddle
Oracleの11グラムR2スキーマのセットアップ:
CREATE TABLE table_name (Subjects, Marks) AS
SELECT 'Maths 1', 68 FROM DUAL UNION ALL
SELECT 'Maths 2', 50 FROM DUAL UNION ALL
SELECT 'Maths 3', 60 FROM DUAL UNION ALL
SELECT 'Maths 4', 80 FROM DUAL;
クエリ1:
SELECT subjects,
marks,
SUM(marks) OVER (ORDER BY subjects) AS add_marks,
100 * SUM(marks) OVER (ORDER BY subjects)/SUM (MARKS) OVER() AS "%marks"
FROM table_name
Results:
| SUBJECTS | MARKS | ADD_MARKS | %marks |
|----------|-------|-----------|--------------------|
| Maths 1 | 68 | 68 | 26.356589147286822 |
| Maths 2 | 50 | 118 | 45.736434108527135 |
| Maths 3 | 60 | 178 | 68.9922480620155 |
| Maths 4 | 80 | 258 | 100 |
出典
2017-10-04 08:32:40
MT0
ないすべてで透明、あなたがやりたい何をすべきか、あなたは何のほかに何をしたいですか? –
@CyrilleMODIANO OPは 'marks'カラムの累積合計を探しています。 – MT0