ORACLE RANK() function

Asked

Viewed 202 times

0

Could someone explain me what is wrong with my syntax/use of the RANK function?

Problem situation: "Rank songs by band so that songs of higher duration occupy the first places. Present band name and music and ranking position."

SELECT MU.NOME, BA.NOME
RANK() OVER (PARTITION BY MU.TEMPO_DURACAO ORDER BY BA.NOME)
FROM MUSICA MU, BANDAS_E_ARTISTAS BA, BANDA BD
WHERE BA.ID = BD.ID
  • Seems to lack the condition of John of "MUSIC" generating an improper Cartesian prodoto.

1 answer

0

Well it seems that your Jay is wrong, you are uniting music, bands and artists and bands, but you are only doing Jay between the bands and the artists, but the songs are nowhere in the Where clause. The ideal would be to have a MU.id_banda = BD.id or something like.

As for rank, he asks to break by band and order by time, so it should be something like this:

SELECT MU.NOME, BA.NOME,
  RANK() OVER (PARTITION BY BA.NOME ORDER BY MU.TEMPO_DURACAO DESC)
FROM MUSICA MU, BANDAS_E_ARTISTAS BA, BANDA BD
WHERE BA.ID = BD.ID AND MU.BANDA_ID = BD.ID

Browser other questions tagged

You are not signed in. Login or sign up in order to post.