Displaying row number in a group by

I needed to add row numbers to a grouped by sql statement in MySQL and came up with this

set @row :=0;
select *,@row:=@row+1 as ‘grid_pos’ from
( select ????? from ????? where x = 576787 and y = 971578 and type = 1 group by z order by z desc limit 3) xx

Advertisements
Displaying row number in a group by