/* Create a accumulation column, perform a nested subquery */ /* This is an example where the subquery is part of the SELECT list */ select vendor, description, pay_date, amount, (select sum(amount) from payment i where i.pay_date <= o.pay_date and MONTH(pay_date) = 3) as cumulative_amount --for Oracle use --TO_CHAR(pay_date,'MM') from payment o order by pay_date; /* Create a accumulation column, perform a nested subquery */ /* This is an example where the subquery is part of the SELECT list */ SELECT course_id, description, price, ( SELECT SUM(price) FROM course i WHERE i.course_id <= o.course_id /*join inner to outer table*/ AND i.course_id > 'X52-9267' /*other inner conditions */ ) AS accum_price FROM course o /*WHERE o.course_id > 'X52-9267'*/ /*other outer conditions*/ ORDER BY o.course_id;