This is what I got from this prompt. Still lots of practice for me since this is challenging to me but grateful that I can practice on my own and learn from my mistakes.
SELECT TOP 10 Manufacturer, ROUND(AVG(((Price_in_thousands)-(year_resale_value))*1000), 2) as Average_Depreciation
FROM Car_sales
WHERE Price_in_thousands IS NOT NULL AND year_resale_value IS NOT NULL
GROUP BY Manufacturer
HAVING COUNT(ID) > 2
ORDER BY ROUND(AVG((Price_in_thousands) - (year_resale_value)*1000), 2)
Great Stretch Problem to get me better versed in SQL. Loved trying to wrap my head around how to do it. Thanks for the challenge!
Here my Answer to the Problem:
SELECT TOP 10 c.Manufacturer, ROUND(AVG(((c.Price_in_thousands)-(c.year_resale_value))*1000),2) AS AvgDepreciation
FROM Car AS c
WHERE c.year_resale_value IS NOT NULL AND c.Price_in_thousands IS NOT NULL
GROUP BY Manufacturer
HAVING COUNT(c.ID) > 1
ORDER BY ROUND(AVG(((c.Price_in_thousands)-(c.year_resale_value))*1000),2) ASC;
Here is my solution! This was a challenge and I had to use some help from my peers, but I think I got it eventually!
SELECT TOP 10 Manufacturer, ROUND(AVG(((Price_in_thousands) - (year_resale_value))*1000),2) AS AVGDepreciation
FROM Car_sales
WHERE Price_in_thousands IS NOT NULL AND year_resale_value IS NOT NULL
GROUP BY Manufacturer
HAVING COUNT (ID) >2
ORDER BY ROUND(AVG(((Price_in_thousands) - (year_resale_value))*1000),2) ;
Here is my answer. The suggestions and hints are helpful, the TOP 10 hint is awesome.
SELECT TOP 10 Manufacturer, ROUND(AVG(((Price_in_thousands)-(year_resale_value))*1000), 2) AS Average_Depreciation
FROM Car_sales
WHERE (((Price_in_thousands)-(year_resale_value))*1000) IS NOT NULL
GROUP BY Manufacturer
HAVING COUNT(ID)>2
ORDER BY ROUND(AVG(((Price_in_thousands)-(year_resale_value))*1000), 2);
1 Like
SELECT TOP 10 Manufacturer, Price_in_thousands
FROM Car_sales;
This is what I was able to start with. I was having trouble getting the year_resale_value column to work, any ideas?
That is a great job. Well done, I’m beginning too but I really like what your were able to do!
Here is my attempt at this problem:
SELECT TOP 10 Manufacturer, ROUND(AVG(((Price_in_thousands)-(year_resale_value))*1000), 2) as Average_Depreciation
FROM Car_sales
WHERE Price_in_thousands IS NOT NULL AND year_resale_value IS NOT NULL
GROUP BY Manufacturer
HAVING COUNT(ID) > 2
ORDER BY ROUND(AVG((Price_in_thousands) - (year_resale_value)*1000), 2)
Great problem! Here is my solution.
SELECT TOP 10 Manufacturer, ROUND(AVG((Price in thousands)-(year_resale_value))*1000), 2) AS AverageDepreciation
FROM Car_sales
WHERE (((Price_in_thousands)-(year_resale_value))*1000)IS NOT NULL
GROUP BY Manufacturer
HAVING COUNT (ID) > 2
ORDER BY ROUND(AVG(((Price_in_thousands)-(year_resale_value))*1000), 2);
Fun challenge! It took me a minute to understand that it was overall depreciation (not average yearly depreciation) but it all made sense in the end
Here’s my code:
SELECT TOP 10 c.Manufacturer, ROUND((AVG(Price_in_thousands-year_resale_value) * 1000), 2) AS AvgDep
FROM Car_sales AS c
WHERE (c.Price_in_thousands) IS NOT NULL AND (c.year_resale_value) IS NOT NULL
GROUP BY c.Manufacturer
HAVING Count(c.ID)>=3
ORDER BY ROUND((AVG(Price_in_thousands-year_resale_value) * 1000), 2)
1 Like
SELECT TOP 10 Manufacturer, ROUND((AVG(Price_in_thousands-[__year_resale_value])*1000),2) AS Average_Depreciation
FROM Car_sales
WHERE Price_in_thousands IS NOT NULL AND [__year_resale_value] IS NOT NULL
GROUP BY Manufacturer
HAVING COUNT(ID)>2
ORDER BY ROUND((AVG(Price_in_thousands-[__year_resale_value])*1000),2);
carsales.yxmd (15.4 KB)
Here’s my solution! Great Alteryx challenge.