sql >> Base de Datos >  >> RDS >> Mysql

MySQL:convierta un valor duplicado en un único con una concatenación de incremento

Parece que solo quieres CONCAT() los valores juntos:

select data, group_row_number, 
  concat(data, cast(group_row_number as char)) as num,
  overall_row_num
from
(
  select data,
        @num := if(@data = `data`, @num + 1, 1) as group_row_number,
        @data := `data` as dummy, overall_row_num
  from
  (
    select data, @rn:[email protected]+1 overall_row_num
    from yourtable, (SELECT @rn:=0) r
  ) x
  order by data, overall_row_num
) x
order by overall_row_num

Consulte SQL Fiddle con demostración