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

Jan Lundeen
Jan Lundeen
5,886 Points

Getting a "AS" syntax error for a query counting the number of orders shipped today [uses DATE("now")].

Hi,

In the DATE and TIME section of Reporting with SQL, I'm getting a "AS" syntax error for a query counting the number of orders shipped today [uses DATE("now")]. Here's the question:

Challenge 1 of 1: 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 today. Alias it to shipped_today.

Here's my query:

SELECT COUNT(*) FROM ORDERS WHERE Status = "shipped" AS "shipped_today" AND ordered_on = DATE(“now”);

Here's the error I received:

SQL Error: near "AS": syntax error

From the question, they don't list all the different statuses. Since the question instructs you to alias the status with shipped_today, I'm assuming that is not the status and that the status should be shipped. However, I'm not sure. I tried taking off the quotes around "shipped_today", but that didn't make a difference. Any ideas?

Thanks,

Jan

3 Answers

Steven Parker
Steven Parker
231,248 Points

The alias is to be applied to the column in the SELECT list.

The question actually instructs you to alias the count. The alias determines the name that will be shown for the column. So you might write:

SELECT COUNT(*) AS "shipped_today" FROM ORDERS WHERE Status = "shipped" AND ordered_on = DATE("now");
Jan Lundeen
Jan Lundeen
5,886 Points

Ok. I thought they were referring to the status field. Thanks for setting me straight.

I tried that query. Now, I"m getting a new error:

SQL Error: no such column: “now” . Not sure why that is happening.

Jan

Andrew Chalkley
Andrew Chalkley
Treehouse Guest Teacher

The quotes around the now aren't " they're curly quotes. If you delete the quotes around now and replace them with quotes in the Code Challenge it should work.

SELECT COUNT(*) AS "shipped_today" FROM ORDERS WHERE Status = "shipped" AND ordered_on = DATE("now");
Jan Lundeen
Jan Lundeen
5,886 Points

Hi Andrew,

The only quotes I have on my keyboard are ". I'm not sure what you mean by curly quotes . Are you referring to {}? There are no quotes mentioned in the code challenge question. Perhaps I'm overlooking something. I took off the quotes and put on the only quotes I have on my keyboard (") and it worked.

Thanks,

Jan

Steven Parker
Steven Parker
231,248 Points

The quotes Andrew was talking about are "word processor quotes". You might have picked them up if you cut and pasted from a document (including challenge instructions).