ComeçarComece gratuitamente

Potência máxima

Às vezes, você pode querer "salvar" os resultados de uma consulta para poder trabalhar mais com os dados. Você pode fazer isso criando uma tabela temporária que permanece no banco de dados até que o SQL Server seja reiniciado. Neste exercício final, você deve selecionar a faixa mais longa de cada álbum e adicioná-la a uma tabela temporária que será criada como parte da consulta.

Este exercício faz parte do curso

Introdução ao SQL Server

Ver Curso

Instruções de exercício

  • Insira dados por meio de uma instrução SELECT em uma tabela temporária chamada #maxtracks.
  • Junte album com artist usando artist_id, e track com album usando album_id.
  • Execute a última instrução SELECT para recuperar todas as colunas da nova tabela.

Exercício interativo prático

Experimente este exercício preenchendo este código de exemplo.

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;
Editar e executar código