Mysql
 sql >> Base de Dados >  >> RDS >> Mysql

Contador MySQL SELECT, Agrupar por

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;