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 trialCharles Webb
1,542 PointsIs this question glitched? SQL
Alright here is the location of the question:
https://teamtreehouse.com/library/reporting-with-sql/aggregate-and-numeric-functions/performing-math
QUESTION:
In an ecommerce database we have a products table with the columns id, name, category, description, price and stock_count. The price is in USD. Write a query that returns the product name and price in Pounds Sterling (GBP). The current exchange rate is 1.4 USD to every 1 GBP. Alias the calculated price to price_gbp. Round to two decimal places.
ANSWER:
SELECT name, ROUND(price / 1.4, 2) price_gdp FROM products;
However, when I run this query I get the response "your query didn't perform the required function"
I'm not sure what's going on here... did I do something wrong?
1 Answer
Eric Butler
33,512 PointsSo close, you just missed the "AS" keyword:
SELECT name, ROUND(price / 1.4, 2) AS price_gbp FROM products;
Try that and see if you got it. Setting "AS" establishes price_gbp
as the alias for what comes before it.
Charles Webb
1,542 PointsCharles Webb
1,542 PointsHi Eric,
Thanks for the help!
From what I understand, the 'AS' keyword is not actually necessary. In any case, that did not resolve the issue. I still receive this error message:
Bummer! Your query didn't perform the correct calculation.
Eric Butler
33,512 PointsEric Butler
33,512 PointsCharles, Hmm....
I just wrote exactly this into the question and got it right:
SELECT name, ROUND(price / 1.4, 2) AS price_gbp FROM products;
Ah! I see what it is -- you (and I in my response) wrote
price_gdp
but it'sprice_gbp
. It's b not d. D'oh!Charles Webb
1,542 PointsCharles Webb
1,542 PointsOh boy. I certainly have egg on my face!
That error message wasn't very helpful!
Thanks for the help Eric! :)
Eric Butler
33,512 PointsEric Butler
33,512 PointsHey we've ALL done that plenty. I'm going to edit my initial answer so it says the right thing, in case anyone stumbles upon this post with a similar question.