Skip to content

Instantly share code, notes, and snippets.

@joepreludian
Last active August 29, 2015 14:02
Show Gist options
  • Save joepreludian/38b4aaea12ae8e42e725 to your computer and use it in GitHub Desktop.
Save joepreludian/38b4aaea12ae8e42e725 to your computer and use it in GitHub Desktop.
Exemplo de uma sql usando variáveis e Ranking
SET @rank = 0;
SELECT
*
FROM
(
SELECT
@rank :=@rank + 1 AS ranking,
id as chamado,
nome,
status
FROM
chamado
WHERE
status = 'IDLE'
ORDER BY
chamado ASC
) AS
chamado_by_rank
WHERE
ranking <= 3; -- ou chamado = <id_do_chamado>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment