Advertisement
Step8rother

Подзапросы в WHERE, задача 5

Jun 27th, 2023
2,135
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
SQL 0.37 KB | Source Code | 0 0
  1. --Выгрузите уникальные названия городов, в которых стоимость заказов превышает среднее значение за 2009 год.
  2.  
  3. SELECT billing_city
  4. FROM invoice
  5. WHERE total >
  6.     (SELECT AVG(total)
  7.      FROM invoice
  8.      WHERE EXTRACT(YEAR FROM CAST(invoice_date AS DATE)) = 2009)
  9. GROUP BY billing_city;
Advertisement
Comments
  • aloushi234
    1 year
    1. нужно было использовать оператор MAX:
    2.  
    3. SELECT billing_city
    4. FROM invoice
    5. WHERE total >
    6.     (SELECT MAX(total)
    7.      FROM invoice
    8.      WHERE EXTRACT(YEAR FROM CAST(invoice_date AS DATE)) = 2009)
    9. GROUP BY billing_city;
Add Comment
Please, Sign In to add comment
Advertisement