Bummer! This is just a preview. You need to be signed in with a Basic account to view the entire video.
Getting Minimum and Maximum Values2:08 with Andrew Chalkley
Finding the minimum and maximum values for particular column can help you get an insight in to what's happening in your data.
To get the maximum value of a numeric column use the
SELECT MAX(<numeric column>) FROM <table>; SELECT MAX(<numeric column>) FROM <table> GROUP BY <other column>;
To get the minimum value of a numeric column use the
SELECT MIN(<numeric column>) FROM <table>; SELECT MIN(<numeric column>) FROM <table> GROUP BY <other column>;
Here, we've got the average order value per user.
What if we wanted to display more statistics for us, or for
someone else to analyze?
For example, you might want to find a record with the largest value, like
the most expensive item in the store, or the highest paid employee in the company.
Let's use another common set of functions to get the maximum and minimum values.
We can use the max and the min functions to find the maximum and minimum values.
It works just like average.
Let's add these two functions to our select statement.
First, MAX(cost) AS Maximum,
then MIN(cost) AS Minimum.
Look at the column in the average, maximum, and minimum functions.
Notice that how each of the functions use the same column.
That's something you can do.
You can include as many functions of printing on the same
column as many times as you like on any query.
This enables you to generate more compelling reports in a single query
without running multiple queries to get each piece of information.
Also, don't forget your commas.
These numeric functions are powerful tools, and simple to use.
You can use them,
not only for currency related queries, but things such as user ratings.
You can get average reviews for movies in a movie database.
You can count each of the reviews by the value given like on Amazon.
Showing the customer's distribution of ratings
helps inform the customer on whether or not they should make a purchase.
You need to sign up for Treehouse in order to download course files.Sign up