💪 Challenge
Create a report to summarize your findings. Include:
- What is the average number of Lego sets released per year?
- What is the average number of Lego parts per year?
- Create a visualization for item 2.
- What are the 5 most popular colors used in Lego parts?
- [Optional] What proportion of Lego parts are transparent?
- [Optional] What are the 5 rarest lego bricks?
- Summarize your findings.
SELECT year,
AVG(sets_per_year)
FROM (
SELECT year,
COUNT(set_num) AS sets_per_year
FROM sets
GROUP BY year) AS sub
GROUP BY year
ORDER BY year ASC
SELECT year,
ROUND(AVG(num_parts), 2) AS avg_parts_per_year
FROM sets
GROUP BY year
ORDER BY year ASC;
SELECT year,
ROUND(AVG(num_parts), 2) AS avg_parts_per_year
FROM sets
GROUP BY year
ORDER BY year ASC;
SELECT c.name AS color_name,
COUNT(c.name) AS color_name_count
FROM inventory_parts AS i
INNER JOIN colors AS c
ON (i.color_id = c.id)
GROUP BY i.color_id, c.name
ORDER BY (color_name_count) DESC
LIMIT 5;
SELECT name LIKE 'Trans%' AS color_type, COUNT(*),
ROUND((COUNT(*) * 100.0 / (SELECT COUNT(*) FROM colors)), 2) as proportion_percentage
FROM colors
GROUP BY color_type;
SELECT p.name, i.quantity
FROM parts AS p
INNER JOIN inventory_parts AS i
USING (part_num)
GROUP BY p.name, i.quantity
ORDER BY i.quantity ASC
LIMIT 5;
We can see from the analysis that the average number of Lego sets released each year typically follows an upward trend, however, it wasn't until 1999 where this really grew from prior years. It continues this larger growth curve throughout the rest of the data, with the exception of two years: 2006 & 2017. Further analysis would be required to draw a conclusion as to why this occured.
Similar to sets, parts also showed a growth when looking at the average released each year. Unlike sets, this is a little more sporadic in each year.
The five most popular colours are: Black White Light Bluish Gray red Dark Bluish Gray
It is no surprise to not see transparent parts in the list as they only make up 16.3% of the overall colours.
Finally the rarest Lego bricks were: ½ CIRCLE W/SLIT 8X5X3 10240stk01 10240stk02 1/4 CIRCLE TILE 1X1 1/4 CIRCLE TILE 1X1 with Lattice Pie Print