- WITH monthly_funds AS(
- SELECT q_month AS month,
- COUNT(DISTINCT name) AS uniq_fund_qty
- FROM(
- SELECT EXTRACT(MONTH from fr.funded_at) AS q_month,
- fr.funded_at,
- f.name
- FROM funding_round AS fr
- LEFT JOIN investment as i ON fr.id=funding_round_id
- LEFT JOIN fund AS f ON f.id=i.fund_id
- WHERE f.country_code = 'USA'
- AND EXTRACT(YEAR from fr.funded_at) IN (2010, 2011, 2012, 2013)
- ) AS q
- GROUP BY q_month
- ),
- monthly_aquired_companies AS(
- SELECT q_month,
- count(companies_aquired) AS companies_aquired_qty,
- sum(deal_sum) AS deals_sum
- FROM(SELECT EXTRACT(MONTH from a.acquired_at) AS q_month,
- acquired_company_id AS companies_aquired,
- price_amount AS deal_sum
- FROM acquisition AS a
- WHERE EXTRACT(YEAR from a.acquired_at) IN (2010, 2011, 2012, 2013)
- GROUP by EXTRACT(MONTH from a.acquired_at), acquired_company_id,a.price_amount
- ORDER BY EXTRACT(MONTH from a.acquired_at)
- ) AS q
- GROUP BY q_month
- )
- SELECT month,
- uniq_fund_qty,
- companies_aquired_qty,
- deals_sum
- FROM monthly_funds AS mf
- JOIN monthly_aquired_companies AS mac ON mf.month=mac.q_month
Untitled
From Alex, 4 Months ago, written in Plain Text, viewed 58 times.
This paste will hop the perch in 1 Second.
URL http://codebin.org/view/24204712
Embed
Download Paste or View Raw
— Expand Paste to full width of browser