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 trialABRAHAM NYONI
9,692 PointsCan 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.
8 Answers
Walter Guerrero
6,843 PointsSELECT 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
johnny lazo
13,433 PointsSELECT COUNT(*) AS ordered_yesterday_and_shipped FROM orders WHERE status = 'shipped' AND ordered_on = DATE("now", "-1 day");
Nolusindiso Hleko
7,358 PointsIs there a reason why Jonny's solution is downvoted I wrote the same and it worked:
SELECT COUNT(*) AS ordered_yesterday_and_shipped FROM orders WHERE status = "shipped" AND ordered_on = DATE("now","-1 day");
ABRAHAM NYONI
9,692 PointsSELECT COUNT(status) AS shipped_yesterday FROM orders WHERE status = "shipped" AND ordered_on = DATE("now", "-1 day"); //This was my code.
Faisal Tariq
1,746 PointsI have the same problem. Using the same code as you but not getting any output.
Aya khaled
Courses Plus Student 1,967 Pointsi recieve error
Robbie Thomas
31,093 PointsWalter 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
5,711 PointsI just did the same mistake by adding twice the "WHERE" =(, but when fixing it, it worked.
Kingsley Atuba
2,891 PointsSELECT COUNT(*) AS shipped_today FROM orders WHERE ordered_on = DATE() AND status = 'shipped';
Judith Copeland
Full Stack JavaScript Techdegree Graduate 17,924 PointsI 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");
D Elis
13,571 PointsD Elis
13,571 PointsHere is the solution: SELECT COUNT(*) AS ordered_yesterday_and_shipped FROM orders WHERE status ='shipped' AND ordered_on = DATE('now', '-1 day')