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

Jiho Song
Jiho Song
16,469 Points

WHAT IS PROBLEM WITH MY SQL COMMAND?

HOW CAN I EXPECT THE VALUE I WOULD RETURN?

IT SEEMINGLY DIDNT MISS THE PURPOSE I GUESS..

HOW DOES THIS COMMAND ACTUALLY RUN IN PROGRAM IF I PUT THE COMMAND LIKE THIS

WHAT DID I GET WRONG?

---------------MY ANSWER---------------

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


----------- QUESTION------------------

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. Type in your command below.

1 Answer

SELECT COUNT(*) AS shipped_today FROM orders 
WHERE ordered_on = DATE('now') and
status = "shipped"

The condition belongs in the WHERE clause

Also Capslock is not really nice D:

Jiho Song
Jiho Song
16,469 Points

DOES CONDITION HAVE TO BE IN WHERE CLAUSE

I JUST WONDER WHY COMPUTER CANNOT UNDERSTAND WHAT I SUPPOSED TO BE MEANT.

AND ACTUALLY IT WORKED HOWEVER RETUREND WRONG VALUE

IT MEAN IT FOUND THE WAY TO CALCULATE BUT NOT IN THE WAY IT SUPPOSED TO BE.

BUT WHY? THANKS A LOT

Jiho Song
Jiho Song
16,469 Points

Sorry for writing while Capslocked

Jiho Song
Jiho Song
16,469 Points

What I expect was it would return the number of count based on how many data with the condition.

but obviously it off the mark