Advertisement
Vitaliy_Novichikhin

Базовый SQL 7/23 слишком много строк

Jul 4th, 2022 (edited)
1,189
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. -- Временная таблица с минимальними значениями
  2. WITH i_min AS (SELECT funded_at,
  3.        MIN(raised_amount)
  4. FROM funding_round
  5. WHERE raised_amount!=0
  6. GROUP BY funded_at
  7. ),
  8. -- Временная таблица с МАКСИмальними значениями
  9. i_max AS
  10. (SELECT funded_at,
  11.        MAX(raised_amount)
  12. FROM funding_round
  13. WHERE raised_amount!= -- в подзапросе МАКСимальное значение инвестиций
  14. (SELECT MAX(raised_amount)
  15. FROM funding_round)
  16. GROUP BY funded_at)
  17. --основной запрос
  18. SELECT i_min.funded_at,
  19.        i_min.min,
  20.        i_max.max
  21. FROM i_min
  22. LEFT JOIN i_max ON i_min.funded_at = i_max.funded_at
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement