Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Databases Reporting with SQL Date and Time Functions Calculating Dates

Can someone help me on this challenge on SQL,CALCULATING DATES.

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 were ordered yesterday and have the status of 'shipped'. Alias it to ordered_yesterday_and_shipped.

Here is the solution: SELECT COUNT(*) AS ordered_yesterday_and_shipped FROM orders WHERE status ='shipped' AND ordered_on = DATE('now', '-1 day')

7 Answers

SELECT COUNT(status) AS "ordered_yesterday_and_shipped" FROM orders WHERE status = "shipped" AND ordered_on = DATE("now", "-1 day");

this worked for me. probly because of your aliashope that helped

SELECT COUNT(status) AS shipped_yesterday FROM orders WHERE status = "shipped" AND ordered_on = DATE("now", "-1 day"); //This was my code.

I have the same problem. Using the same code as you but not getting any output.

Robbie Thomas
Robbie Thomas
31,093 Points

Walter Guererro is right. However, when I did my code, it was like this:

SELECT COUNT(status) AS ordered_yesterday_and_shipped FROM orders WHERE status = "shipped" AND ordered_on = DATE("now", "-1 day");

And it told me it was expecting a count of 14. If you do that code on the SQL playground that goes along with the previous video, the count is 14. Also, I could be wrong about this but do these AS statements not require the use of quotation marks unless they need a string? Doesn't seem right that they want you to put ordered_yesterday_and_shipped with quotes in it.

Marcos Treviño Rodriguez
Marcos Treviño Rodriguez
5,711 Points

I just did the same mistake by adding twice the "WHERE" =(, but when fixing it, it worked.

I tried all the code above, and finally adding quotes around the alias worked for me:

SELECT COUNT(status) AS "ordered_yesterday_and_shipped" FROM orders WHERE status="shipped" AND ordered_on = DATE("now", "-1 day");

i recieve error

johnny lazo
johnny lazo
13,431 Points

SELECT COUNT(*) AS ordered_yesterday_and_shipped FROM orders WHERE status = 'shipped' AND ordered_on = DATE("now", "-1 day");