Skip to content

Instantly share code, notes, and snippets.

@csalgueiro
Forked from jgdoncel/ejemplo_01.sql
Created October 4, 2013 08:48
Show Gist options
  • Save csalgueiro/6822929 to your computer and use it in GitHub Desktop.
Save csalgueiro/6822929 to your computer and use it in GitHub Desktop.
Añadir un campo numerado a una consulta
# La siguiente consulta añade un campo numerado a una consulta:
set @num=0;
select id, @num:=@num+1 AS contando FROM tabla;
# Actualizar un campo
set @num = 0;
update tabla SET campo=(SELECT @num:=@num+1) where id_grupo=10;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment