SHOW:
|
|
- or go back to the newest paste.
1 | - | --Отберите альбомы, названия которых содержат слово 'Rock' и его производные. В этих альбомах должно быть восемь или более треков. Выведите на экран одно число — среднее количество композиций в отобранных альбомах. |
1 | + | --Для каждой страны посчитайте среднюю стоимость заказов в 2009 году по месяцам. Отберите данные за 2, 5, 7 и 10 месяцы и сложите средние значения стоимости заказов. Выведите названия стран, у которых это число превышает 10 долларов. |
2 | ||
3 | - | SELECT AVG(count) |
3 | + | SELECT sub.country |
4 | FROM | |
5 | - | (SELECT a.title, |
5 | + | (SELECT billing_country AS country, |
6 | - | COUNT(t.name) AS count |
6 | + | EXTRACT(YEAR FROM CAST(invoice_date AS date)) AS year, |
7 | - | FROM album as a |
7 | + | EXTRACT(MONTH FROM CAST (invoice_date AS date)) AS month, |
8 | - | INNER JOIN track as t ON a.album_id = t.album_id |
8 | + | AVG(total) AS avg_total |
9 | - | WHERE a.title LIKE '%Rock%' |
9 | + | FROM invoice as i |
10 | - | GROUP BY a.title |
10 | + | WHERE EXTRACT(YEAR FROM CAST(invoice_date AS date)) = 2009 |
11 | - | HAVING COUNT(t.name) >= 8) AS sub; |
11 | + | GROUP BY billing_country, |
12 | EXTRACT(YEAR FROM CAST(invoice_date AS date)), | |
13 | EXTRACT (MONTH FROM CAST(invoice_date AS date))) AS sub | |
14 | WHERE sub.month IN (2, 5, 7, 10) | |
15 | GROUP BY sub.country | |
16 | HAVING SUM(sub.avg_total) > 10; |