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 Counting Results

Bummer! Your query didn't perform the correct count. (wrong diagnostic message)

Link to challenge:

https://teamtreehouse.com/library/reporting-with-sql/aggregate-and-numeric-functions/counting-results-2

Challenge Task 1 of 2

In the library database, how many books are with the genre of "Science Fiction"?

Alias the result as scifi_book_count.

I used this code:

SELECT COUNT(genre) FROM books WHERE genre = "Science Fiction";

..which gave this result:

COUNT(genre)

6

Error message shown:

"Bummer! Your query didn't perform the correct count."


The actual code answer was this:

SELECT COUNT(genre) AS scifi_book_count FROM books WHERE genre = "Science Fiction";

which gave this result:

scifi_book_count

6


So you see the count value of '6' was output for both sets of code,

negating {in my view} the "Bummer! that 'Your query didn't perform the correct count.' "

.

(Although I know in this case it might just have been a situational/database coincidence that

'COUNT(genre)' just happened to equal to 'scifi_book_count' --that they both had a value of 6)

.

However, if you compare the difference between the sql that works (passes the challenge)

and the sql code that doesn't you'll see the first is the missing alias ('AS scifi_book_count')


So the Bummer diagnostic message (to be truly useful) should have been something like:

"You are missing the alias code"


Once I realized the original Bummer diagnostic message was not correct

in failing to point out that the key to getting the 'correct count' was

actually some missing SQL alias code then

I was easily able to solve the second part of the challenge as well with:

SELECT COUNT(author) AS jk_book_count FROM books WHERE author = "J.K. Rowling";

Note:

the use of the keyword 'DISTINCT' (as shown in the previous/accompanying video) doesn't seem to be needed.

Hi James, Thanks for pointing out about the error language being incorrect. I kept thinking we would need to incorporate DISTINCT into the second part of the challenge, and I was surprised that we didn't need to as well. Thanks also for providing the correct answer and a link to the challenge. If I could rate your post up I would!

6 Answers

Andrew Winkler
Andrew Winkler
37,739 Points

Yes. The code errors are a little bit hokey. I'm glad you figured out the correct code is:

SELECT COUNT(*) AS scifi_book_count FROM books WHERE genre = 'Science Fiction';

And

SELECT COUNT(author) AS jk_book_count FROM books WHERE author = "J.K. Rowling";

Thanks Andrew,

But I did get the correct answer (eventually)

I just wanted to make sure the challenge diagnostic was changed

to indicate/reflect that the issue with my first set of sql code was

that an alias was missing, not that the count was wrong.

Andrew Winkler
Andrew Winkler
37,739 Points

Yeah, I think I started answering your question before you were done editing it. Originally, it was an open ended question about the error code, then by the time I submitted my answer you had updated your question with a self-supplied-solution. Props! I updated/edited my response in series.

To Andrew - no biggie..that sort of thing happens all the time on programming

(thanks for the quick, realtime response, though..)

Something else weird --

It most of the other courses if you press the "Get Help" button

it correct assigns your question to the course/syllabus.

For this 'Reporting with SQL' course that syllabus group is:

https://teamtreehouse.com/community/syllabus:2362


However I find I now have to go the long way around and select the "Get Help"

from the video previous to the challenge to get the question

to be assigned to threads specifically devoted to the course

and not just to the "Databases" forum (in general).


I wonder if this is something new that is going to be applicable to all courses

(going forward from this point) or just a one-time "oops!" for this course

(which already has had some issues):

Typo 1: https://teamtreehouse.com/community/typo-in-teachers-notes

Type 2 (should have been addresses, not customers): https://teamtreehouse.com/community/sql-error-no-such-column-firstname-resolved

Note: This was the thread that got 'orphaned' out of the course syllabus forum

even though I used the "Get Help" button on the challenge question page.

It's kinda weird, I tried aliasing without quotes, it didn't work and then added quotes only then it worked! Other than that, I didn't change anything. And for the second code I did exact same as 1st but it didn't work again. I don't what's going on!! My bad!!