IniziaInizia gratis

Potere assoluto

A volte potresti voler "salvare" i risultati di una query per poterci lavorare ancora. Puoi farlo creando una tabella temporanea che rimane nel database finché SQL Server non viene riavviato. In questo esercizio finale, selezionerai la traccia più lunga da ogni album e la aggiungerai a una tabella temporanea che creerai come parte della query.

Questo esercizio fa parte del corso

Introduzione a SQL Server

Visualizza il corso

Istruzioni dell'esercizio

  • Inserisci i dati tramite un'istruzione SELECT in una tabella temporanea chiamata #maxtracks.
  • Fai il join di album con artist usando artist_id, e di track con album usando album_id.
  • Esegui l'istruzione SELECT finale per recuperare tutte le colonne dalla tua nuova tabella.

Esercizio pratico interattivo

Prova a risolvere questo esercizio completando il codice di esempio.

SELECT  album.title AS album_title,
  artist.name as artist,
  MAX(track.milliseconds / (1000 * 60) % 60 ) AS max_track_length_mins
-- Name the temp table #maxtracks
INTO ___
FROM album
-- Join album to artist using artist_id
INNER JOIN artist ON album.artist_id = artist.artist_id
-- Join track to album using album_id
___
GROUP BY artist.artist_id, album.title, artist.name,album.album_id
-- Run the final SELECT query to retrieve the results from the temporary table
SELECT album_title, artist, max_track_length_mins
FROM  #maxtracks
ORDER BY max_track_length_mins DESC, artist;
Modifica ed esegui il codice