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






Sum column for a certain time period

  
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.

   
    
  








Related examples in the same category

1.SUM: total for all NOT NULL values, accepts only numeric datatype values
2.Syntax: SUM([DISTINCT]|[ALL] )
3.GROUP BY function would produce inventory totals distributed across different vendors
4.SUM function and NULLs
5.Using the SUM function with GROUP BY Clause
6.sum with column calculation
7.Add an "OTHER" and "TOTAL" column to the report:
8.Compute sum on salary
9.Sum salary group by department number
10.Sum salary over
11.Sum() function and having clause
12.Doing calculation in sum() function
13.Wrap case when into sum() function