Advertisement
manul1537

Untitled

May 23rd, 2024 (edited)
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. WITH /*d AS (SELECT CAST(DATE_TRUNC ('month', funded_at) AS date) AS dm,
  2.            id AS id_d
  3. FROM funding_round
  4. WHERE EXTRACT(YEAR FROM funded_at) BETWEEN 2010 AND 2013 ),
  5.  
  6. f AS (SELECT DISTINCT name AS name_f,
  7.       id AS id_f
  8. FROM fund
  9. WHERE country_code = 'USA'),
  10.  
  11. top AS (SELECT*,inv.id AS inv_id
  12. FROM f
  13. JOIN investment AS inv ON f.id_f=inv.fund_id
  14. JOIN d ON d.id_d=inv.funding_round_id
  15. JOIN company AS co ON co.id= inv.company_id
  16. JOIN acquisition AS ac ON ac.acquired_company_id=co.id),
  17. */
  18. name_sale AS (
  19. SELECT name AS name_sal,
  20.     country_code AS contry_sale,
  21.     acquired_company_id AS id_sale,
  22.     ROUND(price_amount) AS sum_sale,
  23.     acquired_at AS date_sale
  24. FROM company AS cc
  25. RIGHT JOIN acquisition AS ac ON cc.id=ac.acquired_company_id
  26. WHERE price_amount > 0),
  27.  
  28. round_sale AS (
  29. SELECT fr.id AS id_round,
  30.        fr.company_id AS id_company,
  31.        fr.funded_at AS date_round,
  32.        iv.fund_id    
  33. FROM funding_round AS fr
  34. JOIN investment AS iv ON fr.id=iv.funding_round_id
  35. WHERE fr.funded_at IS NOT NULL
  36. AND EXTRACT(YEAR FROM funded_at) BETWEEN 2010 AND 2013 ),
  37.  
  38. contry_fund AS (
  39. SELECT id_round,
  40.        id_company,
  41.        date_round,
  42.        fund_id,
  43.        name AS fund_name,
  44.        country_code AS fund_country    
  45. FROM round_sale AS rs
  46. JOIN fund AS f ON rs.fund_id=f.id
  47. WHERE investment_rounds > 0
  48.     AND invested_companies >0
  49.     AND country_code = 'USA'
  50.     AND EXTRACT(YEAR FROM date_round) BETWEEN 2010 AND 2013
  51. )
  52. SELECT EXTRACT(MONTH FROM date_round) AS month_round,
  53.         COUNT(DISTINCT acquired_company_id) AS count_company_sale,
  54.        COUNT(DISTINCT fund_id) AS name_fund ,
  55.        
  56.        SUM(price_amount) AS total_sum
  57. FROM contry_fund AS cff
  58. JOIN company AS cc ON cc.id=cff.id_company
  59. JOIN acquisition AS ac ON cc.id=ac.acquired_company_id
  60. WHERE price_amount>0
  61. AND acquired_company_id IS NOT NULL
  62. AND EXTRACT(YEAR FROM date_round) BETWEEN 2010 AND 2013
  63. AND fund_country = 'USA'
  64. --AND EXTRACT(YEAR FROM acquired_at) BETWEEN 2010 AND 2013
  65. GROUP BY EXTRACT(MONTH FROM date_round)
  66.  
  67.  
  68.  
  69. /*s_12 AS (SELECT EXTRACT(MONTH FROM dm) AS month,
  70.        COUNT(DISTINCT name_f) AS name_fond ,
  71.        COUNT( acquired_company_id) AS coun_company,
  72.         SUM(price_amount) AS total_sum
  73. FROM top
  74. WHERE price_amount>0
  75. GROUP BY EXTRACT(MONTH FROM dm))*/
  76.  
  77.  
  78. /*SELECT EXTRACT(MONTH FROM date_round) AS month_round,
  79.        COUNT(DISTINCT fund_id) AS name_fund ,
  80.        COUNT( date_sale) AS count_company_sale,
  81.        SUM(sum_sale) AS total_sum
  82. FROM contry_fund AS cff
  83. FULL JOIN name_sale AS nss ON nss.id_sale=cff.id_company
  84. WHERE sum_sale>0
  85. AND EXTRACT(YEAR FROM date_round) BETWEEN 2010 AND 2013
  86. AND fund_country = 'USA'
  87. GROUP BY EXTRACT(MONTH FROM date_round)*/
  88.  
  89.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement