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

sailor winkelman
sailor winkelman
2,603 Points

COUNT and DATE functions: Count calculation is wrong, but what is it counting?

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.

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

I see that 149 is being returned here, which probably means there is a problem with the DATE("now") condition, or maybe with status = "shipped".

What's happening? Thank you!

2 Answers

The question needs to be re-worded.

"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."

There is nothing to compare on to show that it was shipped today. There is a status of "shipped". The only date you can compare on is when it was ordered on. The question isn't asking for the date it was ordered, it's asking for the date shipped.

Steven Parker
Steven Parker
231,261 Points

:point_right: It doesn't look like you are comparing anything to the date. Perhaps you meant something like this:

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