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

Vladislav Mavrin
PLUS
Vladislav Mavrin
Courses Plus Student 3,125 Points

Stuck with the coding challenge

Hi, would appreciate if someone could help me with this task

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 think the task is missing to give the name of a column that contains infirmation about shipping date, otherwise what do we have to compare DATE ("now") with?

My query gives 149..

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

2 Answers

Vladislav Mavrin
PLUS
Vladislav Mavrin
Courses Plus Student 3,125 Points

Well, it seems to be that the question itself is wrong. It should ask to show all the items that were ordered today, not shipped today, because we do not have any data on shipping date.

Where coding is concerned: Count(*) should work. AS looks fine. FROM looks fine. WHERE status="shipped" is problematic in practice, but might be correct here. I don't know. AND DATE("now") looks really odd. I hope that is a dynamic script with proper syntax, but something is still wrong here.

We should probably assume they ship on the same day something was ordered, which is another problematic practice. Try "AND ordered_on=DATE("now")". If that fails, look to join with a table that has shipping date explicitly stated.

I'm inclined to agree with Mavrin. The orders table does not show if it was shipped today or just in shipping (shipped yesterday for instance). Without assumptions, this table could tell you if something was moving, but not when it started the journey. "Problematic in practice" is my response to academics trying to convey an idea that wouldn't work outside the classroom. The idea isn't necessarily wrong, but people make incorrect assumptions and mistakes... How many different ways can you misspell "shipped"?