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,092 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.

Judith Copeland
seal-mask
PLUS
.a{fill-rule:evenodd;}techdegree seal-36
Judith Copeland
Full Stack JavaScript Techdegree Graduate 17,804 Points

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,338 Points

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