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

SQL is saying "Your count is wrong" and not aliasing it as I am requesting

In SQL the test is asking for this:

In an ecommerce database there's an orders table with the columns id, product_id, user_id, address_id, ordered_on, status and cost. Count the total number of orders that have the status of shipped today. Alias it to shipped_today.

I am writing:

SELECT COUNT (*) FROM orders AS shipped_today WHERE status = "shipped" AND ordered_on = DATE("now");

Which returns:

COUNT(*) 13

and am getting it wrong, where it says:

Bummer! You're count calculation was wrong. Was expecting the count of 13.

Can anyone explain what is going on? I can't understand why this won't work, it seems to work fine in the SQL Playground.

Thanks!

2 Answers

Steven Parker
Steven Parker
231,248 Points

:point_right: You should apply the alias to the column, not the table.

The count is actually correct, but it's not being recognized because of the column name. So instead of this:

SELECT COUNT (*) FROM orders AS shipped_today ...

You should write this:

SELECT COUNT(*) AS shipped_today FROM orders ...

Thank you!