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!
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
Brendan WhitingFront End Web Development Techdegree Graduate 84,733 Points
How do we know what date the order was shipped on?
Here is the challenge:
Challenge Task 1 of 1: 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 toshipped_today.
The schema gives us the date it was ordered on, and the status - either "shipped" or "placed". It doesn't tell us what date the order was shipped, just whether its status is shipped or not as of right now. So this is my attempt:
This is my attempt: SELECT COUNT(*) AS shipped_today FROM orders WHERE status = "shipped";
It says "Bummer! You're missing the DATE() function.
Where am I supposed to put the date function?
Steven Parker227,141 Points
Having a status of "shipped" is clearly not sufficient to insure it was shipped today. And if it was ordered today and the status is already "shipped", then it must have been shipped today. But that doesn't account for things that might have been shipped today but were ordered on other days!
I thought this was a bit odd myself, but I didn't report it. I figured what they meant by "shipped today" was "ordered and shipped today".
Perhaps you'd want to report it as a bug to Treehouse Support.
Marcia Haledjian7,562 Points
This is the correct code:
SELECT COUNT(*) AS shipped_today FROM orders WHERE status = "shipped" AND ordered_on = DATE("now");
Dwayne Pate12,249 Points
Not sure if has been updated, but the question is currently poorly written for the query that is supposed to be written.
Shailesh Lakku4,025 Points
I guess expected answer is this and it worked for me.
SELECT COUNT(*) AS "shipped_today" FROM orders WHERE status = "shipped" AND ordered_on = DATE("now")
SELECT COUNT(*) AS shipped_today FROM orders WHERE status = "shipped" AND ordered_on = DATE('now');
I had to write mine like this for it to pass.
Writing ("now") wouldn't allow me to pass.
I agree this was worded oddly, especially considering the video we watched prior to the quiz.
Yep question still broken, and unanswerable given the information provided...
select count(*) as shipped_today from orders where status = 'shipped' and ordered_on= date('now');
Issue for me was writing DATE("now") instead of DATE('now')