Advertisement
Step8rother

Операторы LEFT OUTER JOIN и RIGHT OUTER JOIN, задача 2

Jun 27th, 2023
2,188
2
Never
3
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
SQL 0.41 KB | Source Code | 2 0
  1. --Посчитайте для каждого года число уникальных названий купленных треков.
  2.  
  3. SELECT EXTRACT(YEAR FROM CAST(i.invoice_date AS DATE)) AS year_of_invoice,
  4.        COUNT(DISTINCT t.name) AS unique_track_count
  5. FROM track AS t
  6. LEFT JOIN invoice_line AS il ON t.track_id = il.track_id
  7. LEFT JOIN invoice AS i ON il.invoice_id = i.invoice_id
  8. GROUP BY year_of_invoice;
Advertisement
Comments
  • trawayad
    1 year
    # text 0.12 KB | 0 0
    1. привет. в полученном результате выдает ошибку - слишком много строк.
  • Alexend
    1 year
    # text 0.07 KB | 0 0
    1. в седьмой строке LEFT на RIGHT поменять надо
  • t7235
    1 year
    # text 0.32 KB | 0 0
    1. либо немного изменить
    2.  
    3. SELECT EXTRACT(YEAR FROM CAST(i.invoice_date AS DATE)) AS year_of_invoice,
    4. COUNT(DISTINCT t.name) AS unique_track_count
    5. FROM invoice AS i
    6. LEFT JOIN invoice_line AS il ON i.invoice_id = il.invoice_id
    7. LEFT JOIN track AS t ON il.track_id = t.track_id
    8. GROUP BY year_of_invoice;
Add Comment
Please, Sign In to add comment
Advertisement