set @num = 0, @old=0;
select a.*, b.num from (
select group_concat(id) gid, count(fg) num from (
select id, (@num:=@num + (@old!=data1)) fg, (@old:=data1) fo
from xxxx
) tmp group by fg
) b
left join xxxx a
on concat(',', b.gid, ',') like concat('%,',a.id, ',%')