Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Databases Reporting with SQL Aggregate and Numeric Functions Calculating the Minimum and Maximum Values

A little Lost what am i missing

SELECT ratings, MAX(rating) AS "star_max", MIN(rating) AS "star_min" FROM reviews ORDER BY ratings;

8 Answers

Steven Parker
Steven Parker
231,248 Points

You're close, but:

  • the table has no "ratings" (plural) field, and the instructions only asked for min and max
  • you won't need ORDER BY
  • you will need a WHERE clause to limit the calculations to just "Star Man" ratings

SELECT rating, WHERE ID = 6 MAX(rating) as "star_max" AND MIN(rating) as "star_min" FROM reviews;

Steven Parker
Steven Parker
231,248 Points

As I mentioned before, the instructions only asked for min and max (not "rating" itself). And a WHERE clause always comes after the FROM clause. And you'll want to test "movie_id" instead of "ID".

SELECT rating FROM reviews WHERE movie_id = 6 MAX as "star_max" AND MIN as "star_min"; i still get an error most like gonna a take a break for a while

Steven Parker
Steven Parker
231,248 Points

The original code you started with had a closer SELECT clause, the min and max functions and aliases were fine but the "ratings" just didn't need to be there.

thanks again

define results please

SELECT rating FROM reviews WHERE ID =6 MAX(rating) AS "star_max", MIN(rating) AS "star_min";

it is still off i seem to be missing somehting i am just not seeing;

Steven Parker
Steven Parker
231,248 Points

The functions and aliases need to be in the SELECT clause (as you had originally). And as I mentioned before, you'll want to test "movie_id" instead of "ID".

SELECT rating FROM reviews WHERE "movie_id" = 6, MAX(rating) AS "star_max", MIN(rating) AS "star_min"

i see what you are saying but i think there is one piece missing.

Steven Parker
Steven Parker
231,248 Points

The functions and aliases still need to be in the SELECT clause (as you had originally), but rating by itself does not. And movie_id should not be in quotes.

SELECT rating FROM reviews WHERE movie_id = 6 MAX(rating) AS "star_max", MIN(rating) AS "star_min";

Steven Parker
Steven Parker
231,248 Points

I think we have a misunderstanding of the terms. To be clear, when I talk about the "SELECT clause", I mean the area after the word SELECT but before FROM.

And "rating" should not be there, but the functions and aliases should (as in your very first example).

SELECT rating FROM reviews, MAX(rating) AS "star_max", MIN(rating) AS "star_min" WHERE movie_id =6; still wrong

got in now thanks i see where i was messing up .. you are really helpful