Skip to content

Instantly share code, notes, and snippets.

@cpcloud
Created October 3, 2018 20:06
Show Gist options
  • Save cpcloud/120202a0f288324aaa273de74752ca2f to your computer and use it in GitHub Desktop.
Save cpcloud/120202a0f288324aaa273de74752ca2f to your computer and use it in GitHub Desktop.
Buggy SQL Query
SELECT *,
acq_ipos / num_investments AS acq_rate
FROM (
SELECT CASE WHEN i.investor_name IS NULL THEN ‘NO INVESTOR’
ELSE i.investor_name
END AS “Investor name”,
COUNT(DISTINCT c.permalink) AS num_investments,
COUNT(DISTINCT
CASE WHEN c.status IN (‘ipo’, ‘acquired’) THEN c.permalink
END) AS acq_ipos
FROM crunchbase_companies
LEFT JOIN crunchbase_investments
ON c.permalink = i.company_permalink
GROUP BY 1
ORDER BY 2 DESC
) t
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment