"ActiveRecord Basics" was retired on July 1, 2018. You are now viewing the recommended replacement.
Well done!
You have completed Reporting with SQL!
You have completed Reporting with SQL!
Learn how to select a SQL max value or min value for a particular column, which will help you get insight into what's happening in your data.
To get the maximum value of a numeric column use the MAX()
function.
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 MIN()
function.
SELECT MIN(<numeric column>) FROM <table>;
SELECT MIN(<numeric column>) FROM <table> GROUP BY <other column>;
Cheat Sheets
Related Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign upRelated Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign upHere, 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 upYou need to sign up for Treehouse in order to set up Workspace
Sign up