Untitled

From Soft Lion, 4 Months ago, written in Plain Text, viewed 52 times.
URL http://codebin.org/view/f1726239 Embed
Download Paste or View Raw
  1. WITH
  2.  
  3. t1 AS (SELECT funding_round_id, company_id, fund_id
  4.        FROM investment),
  5.  
  6. t2 AS (SELECT id, funded_at
  7.        FROM funding_round
  8.        WHERE EXTRACT(YEAR FROM funded_at) BETWEEN 2010 AND 2013
  9.        ),
  10.  
  11. t3 AS (SELECT acquired_company_id, price_amount
  12.        FROM acquisition
  13.        WHERE EXTRACT(YEAR FROM acquired_at) BETWEEN 2010 AND 2013
  14.       )
  15.  
  16.  
  17. SELECT EXTRACT(MONTH FROM t2.funded_at),
  18.        COUNT(DISTINCT fund.id) as f_count,
  19.        COUNT(t3.acquired_company_id) as a_count,
  20.        SUM(t3.price_amount) as p_sum
  21. FROM t1
  22. JOIN t2 ON t1.funding_round_id = t2.id
  23. JOIN t3 ON t1.company_id = t3.acquired_company_id
  24. JOIN fund ON t1.fund_id = fund.id
  25. WHERE fund.country_code = 'USA'
  26. GROUP BY EXTRACT(MONTH FROM t2.funded_at)

Reply to "Untitled"

Here you can reply to the paste above