We use the AVG () function to determine the average of all the values in a column. These examples use the columns MonthsWithOwner and OwnerAge

Select AVG (MonthsWithOwner) AS AvgTimeWithOwner

FROM Cat;

OUTPUT

AvgTimeWithOwner
—————-

37

(1 row(s) affected)

 

SELECT AVG(OwnerAge) AS 'Average Pet Owner Age'
FROM PetOwner;
OUTPUT

Average Pet Owner Age
———————
41

(1 row(s) affected)

 

As with the other functions, we can add a where clause to include only specific criteria. This example will give us the average pet ownership time for cats that are Orange.

Select AVG (MonthsWithOwner) AS AvgTimeWithOwner

FROM Cat

WHERE ColorOfCat = 'Orange';

OUTPUT

AvgTimeWithOwner
—————-

44

(1 row(s) affected)