
Did you know that the average return from investing in stocks is 10% yearly! But who wants to be average?!
You have been asked to support an investment firm by analyzing trends in high-growth companies. They are interested in understanding which industries produce the highest valuations and the rate at which new high-value companies emerge. Providing this information gives them a competitive insight into industry trends and how they should structure their portfolio looking forward.
You have been given access to their unicorns database, which contains the following tables:
dates
| Column | Description |
|---|---|
| company_id | A unique ID for the company. |
| date_joined | The date that the company became a unicorn. |
| year_founded | The year that the company was founded. |
funding
| Column | Description |
|---|---|
| company_id | A unique ID for the company. |
| valuation | Company value in US dollars. |
| funding | The amount of funding raised in US dollars. |
| select_investors | A list of key investors in the company. |
industries
| Column | Description |
|---|---|
| company_id | A unique ID for the company. |
| industry | The industry that the company operates in. |
companies
| Column | Description |
|---|---|
| company_id | A unique ID for the company. |
| company | The name of the company. |
| city | The city where the company is headquartered. |
| country | The country where the company is headquartered. |
| continent | The continent where the company is headquartered. |
Solution Plan
The initial task is to identify the three best-performing industries based on the number of new unicorns created over the last three years (2019, 2020, and 2021) combined.
From there, I will write a query to return the industry, the year, the number of companies in these industries that became unicorns each year in 2019, 2020, and 2021, along with the average valuation per industry per year, converted to billions of dollars and rounded to two decimal places!
As the firm is interested in trends for the top-performing industries, your results should be displayed by industry, then year in descending order.
In [12]:
WITH top_3 AS (SELECT industry, COUNT(company) AS num_unicorn FROM dates
LEFT JOIN companies
USING(company_id)
LEFT JOIN industries
USING(company_id)
WHERE to_char(date_joined,'YYYY') IN ('2019','2020','2021')
GROUP BY industry
ORDER BY num_unicorn DESC
LIMIT 3)
SELECT industry,
CASE WHEN to_char(date_joined, 'YYYY') = '2019' THEN 2019
WHEN to_char(date_joined, 'YYYY') = '2020' THEN 2020
WHEN to_char(date_joined, 'YYYY') = '2021' THEN 2021
END AS year,
COUNT(company) AS num_unicorns, ROUND(AVG(valuation)/1000000000,2) AS average_valuation_billions
FROM dates
INNER JOIN funding
USING(company_id)
INNER JOIN industries
USING(company_id)
INNER JOIN companies
USING(company_id)
WHERE industry IN (SELECT industry FROM top_3) AND (to_char(date_joined,'YYYY') IN ('2019','2020','2021') )
GROUP BY industry, year
ORDER BY industry, year DESC;
Out[12]:
| industry | year | num_unicorns | average_valuation_billions | |
|---|---|---|---|---|
| 0 | E-commerce & direct-to-consumer | 2021 | 47 | 2.47 |
| 1 | E-commerce & direct-to-consumer | 2020 | 16 | 4.00 |
| 2 | E-commerce & direct-to-consumer | 2019 | 12 | 2.58 |
| 3 | Fintech | 2021 | 138 | 2.75 |
| 4 | Fintech | 2020 | 15 | 4.33 |
| 5 | Fintech | 2019 | 20 | 6.80 |
| 6 | Internet software & services | 2021 | 119 | 2.15 |
| 7 | Internet software & services | 2020 | 20 | 4.35 |
| 8 | Internet software & services | 2019 | 13 | 4.23 |






Leave a comment