Advertisement
Step8rother

Подзапросы в FROM, задача 3

Jun 27th, 2023 (edited)
1,624
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
SQL 0.98 KB | Source Code | 0 0
  1. --Найдите средние значения полей, в которых указаны минимальная и максимальная длительность отобранных фильмов. Отобразите только два этих поля. Назовите их avg_min_length и avg_max_length соответственно.
  2.  
  3. SELECT AVG(min_length) AS avg_min_length,
  4.        AVG(max_length) AS avg_max_length
  5. FROM
  6.   (SELECT top.rating,
  7.           MIN(top.LENGTH) AS min_length,
  8.           MAX(top.LENGTH) AS max_length,
  9.           AVG(top.LENGTH) AS avg_length,
  10.           MIN(top.rental_rate) AS min_rental_rate,
  11.           MAX(top.rental_rate) AS max_rental_rate,
  12.           AVG(top.rental_rate) AS avg_rental_rate
  13.    FROM
  14.      (SELECT title,
  15.              rental_rate,
  16.              LENGTH,
  17.              rating
  18.       FROM movie
  19.       WHERE rental_rate > 2
  20.       ORDER BY LENGTH DESC
  21.       LIMIT 40) AS top
  22.    GROUP BY top.rating
  23.    ORDER BY avg_length) AS sub;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement