Advertisement
AliaksandrLet

Задача 23

Jun 22nd, 2022 (edited)
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. WITH
  2. avg AS (
  3.     SELECT
  4.         AVG(funding_total) AS avg_total,
  5.         country_code AS country,
  6.         EXTRACT(YEAR FROM CAST(founded_at AS DATE)) AS years
  7.     FROM
  8.         company
  9.     GROUP BY
  10.         country_code,
  11.         years
  12. )
  13.  
  14. SELECT
  15.     a1.country,
  16.     a1.avg_total AS avg2011,
  17.     a2.avg_total AS avg2012,
  18.     a3.avg_total AS avg2013
  19. FROM
  20.     avg AS a1
  21.     INNER JOIN avg AS a2 ON a2.country = a1.country
  22.     INNER JOIN avg AS a3 ON a3.country = a1.country
  23. WHERE
  24.     a1.years = 2011
  25.     AND a2.years = 2012
  26.     AND a3.years = 2013
  27. ORDER BY
  28.     avg2011 DESC
  29.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement