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. 0:00 What if we wanted to display more statistics for us, or for 0:04 someone else to analyze? 0:08 For example, you might want to find a record with the largest value, like 0:10 the most expensive item in the store, or the highest paid employee in the company. 0:15 Let's use another common set of functions to get the maximum and minimum values. 0:20 We can use the max and the min functions to find the maximum and minimum values. 0:27 It works just like average. 0:33 Let's add these two functions to our select statement. 0:36 First, MAX(cost) AS Maximum, 0:40 then MIN(cost) AS Minimum. 0:50 Look at the column in the average, maximum, and minimum functions. 1:00 Notice that how each of the functions use the same column. 1:08 That's something you can do. 1:12 You can include as many functions of printing on the same 1:14 column as many times as you like on any query. 1:17 This enables you to generate more compelling reports in a single query 1:21 without running multiple queries to get each piece of information. 1:25 Also, don't forget your commas. 1:35 These numeric functions are powerful tools, and simple to use. 1:40 You can use them, 1:45 not only for currency related queries, but things such as user ratings. 1:46 You can get average reviews for movies in a movie database. 1:51 You can count each of the reviews by the value given like on Amazon. 1:55 Showing the customer's distribution of ratings 2:00 helps inform the customer on whether or not they should make a purchase. 2:03
You need to sign up for Treehouse in order to download course files.Sign up