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 trial

Databases

donald kaiser
donald kaiser
9,736 Points

I keep getting a syntax error when trying to count the total number of columns from an ecommerce database.

SELECT COUNT(*) FROM orders WHERE status = "shipped today" AS shipped_today AND ordered_on = DATE("now");

SQL Error: near "AS": syntax error

https://teamtreehouse.com/library/reporting-with-sql/date-and-time-functions/todays-report

2 Answers

Christopher Debove
PLUS
Christopher Debove
Courses Plus Student 18,373 Points

You can't have a "AS" in a where clause. This is the count(*) you want to alias and the value you want is "shipped" not "shipped today" (The today word is for the date condition). So :

SELECT COUNT(*) AS shipped_today FROM orders WHERE status = "shipped" AND ordered_on = DATE("now");
donald kaiser
donald kaiser
9,736 Points

Oh wow, ok my thinking was totally backwards here. That totally worked. Thanks!