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 trialSobin Sebastian
5,348 PointsI don't get it, whats wrong ?
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 yesterday. Alias it to shipped_yesterday.
my answers is SELECT COUNT(*) AS shipped_today FROM orders WHERE status = "shipped" AND ordered_on = DATE("now", "-1 day");
but its saying wrong can please someone help me understand what wrong am i doing here?
https://teamtreehouse.com/library/reporting-with-sql/date-and-time-functions/calculating-dates-2
7 Answers
Sobin Sebastian
5,348 Pointsthe correct answer is SELECT COUNT(*) AS shipped_yesterday FROM orders WHERE status = "shipped" AND ordered_on = DATE("now", "-1 day");
Peter Hope
Courses Plus Student 5,849 PointsThis also works - SELECT COUNT(*) AS ordered_yesterday_and_shipped FROM orders WHERE status = "shipped" AND ordered_on = DATE("now", "-1 day");
V. T van der Vlugt
14,883 Pointscan't you use the NOW() function?
for example(information from MYSQL DATE ref
SELECT COUNT(*) AS shipped_today
FROM orders
WHERE status = "shipped" AND ordered_on = NOW() - INTERVAL 1 DAY;
Hope this helps
Sobin Sebastian
5,348 Pointsnop, i tried its saying You're missing the DATE() function. This is the question https://teamtreehouse.com/library/reporting-with-sql/date-and-time-functions/calculating-dates-2
Steven Parker
231,261 PointsIt looks like V.T. was referring to MySQL syntax. Treehouse uses Sqlite. And you may have given the wrong link. It looks like you're working on the Today's Report challenge.
In Sqlite, the current date is represented by: DATE("now").
And since you're only interested in today, you won't need to perform any calculations on the date.
Sobin Sebastian
5,348 Pointssorry this is the correct question https://teamtreehouse.com/library/reporting-with-sql/date-and-time-functions/calculating-dates-2
Rakeeb Jalaldeen
3,847 PointsThis worked for me,
SELECT COUNT(*) AS ordered_yesterday_and_shipped FROM orders WHERE status = "shipped" AND ordered_on BETWEEN DATE("now", "-1 day") AND DATE("now", "-1 day");
Erik Sorensen
13,846 PointsSobin, You are correct. My mistake. I was looking at the wrong question. It is:
SELECT COUNT(*) AS shipped_yesterday FROM orders WHERE status = "shipped" AND ordered_on = DATE("now", "-1 day");
roberto lopez
Courses Plus Student 2,300 PointsSELECT COUNT(*) AS shipped_yesterday FROM orders WHERE status = "shipped" AND ordered_on = DATE("now", "-1 day"); this give me an error still why
Rose Mathurin
2,882 PointsThis still gives me an error too!
Erik Sorensen
13,846 PointsErik Sorensen
13,846 PointsLooks like you figured it out. Sorry, I was looking at the wrong question. I save the questions and my answers so I can go back and review. Glad you figured it out!
Joy Manuel
6,464 PointsJoy Manuel
6,464 PointsThis is exactly what I had. So glad I'm understanding SQL. Hoping that this can be the same momentum going into other languages. Hope everyone's progression goes well.