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

COMMA placement in counting groups of Rows

Hello, For the first question of "In the library database there's a books table. There are id, title, author, genre and first_published columns.

Count all the books in each genre. Include the genre column first and the genre_count as the second column of information."

I determined the answer, but wanted to understand the comma placement that held me up in figuring this out.

As I understood it from earlier videos (don't recall which one), the comma was used to append a column... I was initially answering this as blah blah blah blah GROUP BY genre, genre_count. (which was wrong)

Does the combination of genre, and the count function at the beginning create the new column?

Why wouldn't this be at the end of the syntax, like I initially thought?

Thanks!

Megan Amendola
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Megan Amendola
Treehouse Teacher

Hi, Jordan! Can you post a link to which video or challenge this question goes with? That way we can see what course you're on :)

Count(genre) as count would be a column and would show the count of items containing each genre

1 Answer

Jurgen de Vries
Jurgen de Vries
14,554 Points

In the first part of the answer the comma is used to append the new column with the count value.

At the end you specify how the results should be grouped. Since you want to count al the books by genre, you only group by the genre column.

If you want to group by multiple columns (e.g. genre and author) you can use the comma in a group by as well.