GROUP BY function would produce inventory totals distributed across different vendors : SUM « Aggregate Functions « Oracle PL / SQL






GROUP BY function would produce inventory totals distributed across different vendors

   
SQL>
SQL> CREATE TABLE MyProduct
  2  (
  3    MAKER  VARCHAR (25),
  4    MODEL  VARCHAR (25),
  5    PRICE  NUMERIC
  6  );

Table created.

SQL>
SQL> INSERT INTO MyProduct VALUES('CHRYSLER','CROSSFIRE',33620);

1 row created.

SQL> INSERT INTO MyProduct VALUES('CHRYSLER','300M',29185);

1 row created.

SQL> INSERT INTO MyProduct VALUES('HONDA','CIVIC',15610);

1 row created.

SQL> INSERT INTO MyProduct VALUES('HONDA','ACCORD',19300);

1 row created.

SQL>
SQL> INSERT INTO MyProduct VALUES('FORD','MUSTANG',15610);

1 row created.

SQL> INSERT INTO MyProduct VALUES('FORD','LATESTnGREATEST',NULL);

1 row created.

SQL> INSERT INTO MyProduct VALUES('FORD','FOCUS',13005);

1 row created.

SQL>
SQL>
SQL> SELECT
  2     Maker,
  3     SUM(price) total
  4  FROM MyProduct
  5  GROUP BY maker;

MAKER                        TOTAL
------------------------- --------
HONDA                     ########
FORD                      ########
CHRYSLER                  ########

SQL>
SQL> drop table MyProduct;

Table dropped.

SQL>

   
    
  








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.SUM function and NULLs
4.Using the SUM function with GROUP BY Clause
5.sum with column calculation
6.Add an "OTHER" and "TOTAL" column to the report:
7.Compute sum on salary
8.Sum column for a certain time period
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