Table of Contents
The outline of your notebook will show up here. You can include headings in any text cell by starting a line with #
, ##
, ###
, etc., depending on the desired title hierarchy.
Did you know that the average return from investing in stocks is 10% per year! 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 are producing the highest valuations and the rate at which new high-value companies are emerging. Providing them with this information gives them a competitive insight as to 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. |
SELECT * FROM companies
WITH top_industries AS (
SELECT i.industry, COUNT(*) as num_new_unicorns
FROM dates d
JOIN industries i ON d.company_id = i.company_id
WHERE d.date_joined BETWEEN '2019-01-01' AND '2021-12-31'
GROUP BY i.industry
ORDER BY num_new_unicorns DESC
LIMIT 3
),
yearly_rankings AS (
SELECT i.industry, EXTRACT(YEAR FROM d.date_joined) as year, COUNT(*) as num_unicorns, ROUND(AVG(f.valuation)/1000000000, 2) as average_valuation_billions
FROM dates d
JOIN funding f ON d.company_id = f.company_id
JOIN industries i ON d.company_id = i.company_id
JOIN top_industries t ON i.industry = t.industry
WHERE EXTRACT(YEAR FROM d.date_joined) IN (2019, 2020, 2021)
GROUP BY EXTRACT(YEAR FROM d.date_joined), i.industry
ORDER BY i.industry, year DESC
)
SELECT *
FROM yearly_rankings;
/* This query uses two CTEs: top_industries and yearly_rankings.
The first CTE top_industries identifies the top-performing industries based on the number of new unicorns created over the last three years, using the same query as before.
The second CTE yearly_rankings then joins the top_industries CTE with the dates, funding, and industries tables, using the EXTRACT function to filter for companies that became unicorns in 2019, 2020, or 2021. It then calculates the number of unicorns in each industry in each year, as well as the average valuation per industry per year, converted to billions of dollars and rounded to two decimal places. Finally, the results are ordered by industry and year in descending order.
The main query then selects all columns from the unicorn_trends CTE, which provides 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, for the top-performing industries. */