Syntax: AVG ([DISTINCT]|[ALL] ) : AVG « Aggregate Functions « Oracle PL / SQL






Syntax: AVG ([DISTINCT]|[ALL] )

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

Table created.

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

1 row created.

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

1 row created.

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

1 row created.

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

1 row created.

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

1 row created.

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

1 row created.

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

1 row created.

SQL>
SQL>
gather some statistical information about the cars in the CARS table
SQL>
SQL> SELECT
  2       AVG(price) average_price
  3  FROM cars;
SQL>
SQL>
SQL>
SQL> drop table cars;

Table dropped.

SQL>

   
    
  








Related examples in the same category

1.AVG: returns the average of all NOT NULL values passed into the function
2.find the average of the uniquely priced cars: use the DISTINCT modifier:
3.To find out the average price for each manufacturer: use the GROUP BY clause
4.AVG function and NULLs
5.Average salary in Toronto: AVG with where clause
6.AVG(DISTINCT salary)
7.GROUP BY clause and AVG() function
8.Having with avg
9.Use avg and nvl together
10.Use NVL in set statement
11.Average Price Per Department
12.Average Price Per Departments Having More Than 3 Products
13.Employees whose salary is more than average salary
14.Employees whose salary is more than average salary(use having clause only)