We can use some of the simple math functions—Min, Max, AVG, and SUM—as basic examples of functions we can use in our queries. Each uses the same format and you will notice we only have one column in our select query. I have also used an alias in each example query below.

 

Min Function

We use the MIN () function to determine the smallest amount or number in a column. While there may be more than one row with the smallest number, only one row will be returned. OUTPUT...

Max Function

We use the MAX () function to determine the largest amount or number in a column. While there may be more than one row with the largest number, only one row will be returned. OUTPUT...

Avg Function

We use the AVG () function to determine the average of all the values in a column. These examples use the columns MonthsWithOwner and OwnerAge OUTPUT AvgTimeWithOwner ---------------- 37 (1 row(s)...

Sum Function

We use the SUM () function to determine the total value of all the rows in a column. This example uses MonthsWithOwner. OUTPUT MonthsWithOwner ------------------ 10055 (1 row(s)...

I

Want to follow along on your own database?

Do you want to follow along with the examples?  We have created a sample database you can use to follow along and try in your own database.  Go to the download page and follow the instructions.  Have fun on the SQL trail!