Mysql
 sql >> Database >  >> RDS >> Mysql

MySQL SELECT Contatore, Raggruppa per

SELECT @rn := if(@g = tbl_albums.id, @rn+1, 1) rownumber,
       tbl_tracks.title, tbl_albums.title,
  @g := tbl_albums.id
FROM (select @g:=null, @rn:=0) initvars
CROSS JOIN tbl_tracks
INNER JOIN tbl_albums on tbl_tracks.album_id = tbl_albums.id
ORDER BY tbl_albums.id, tbl_tracks.title;