Sum column for a certain time period : SUM « Aggregate Functions « Oracle PL/SQL Tutorial






SQL> CREATE TABLE sales(
  2    product_id            NUMBER(6),
  3    cid           NUMBER,
  4    time_id               DATE,
  5    channel_id            CHAR(1),
  6    promo_id              NUMBER(6),
  7    sold         NUMBER(3),
  8    amount                NUMBER(10,2),
  9    cost                  NUMBER(10,2)
 10  );

Table created.

SQL>
SQL> select sum(amount)
  2  from sales
  3  where time_id between to_date('2006-02-01', 'YYYY-MM-DD') and to_date('2006-02-28', 'YYYY-MM-DD');



SUM(AMOUNT)
-----------

1 row selected.

SQL>
SQL> drop table sales;

Table dropped.








12.8.SUM
12.8.1.SUM(x) adds all the values in x and returns the total.
12.8.2.Sum with 'group by cude'
12.8.3.Sum with null value
12.8.4.Sum column for a certain time period
12.8.5.Sum() function and having clause
12.8.6.Sum salary group by department number