Last active
August 29, 2015 14:02
-
-
Save joepreludian/38b4aaea12ae8e42e725 to your computer and use it in GitHub Desktop.
Exemplo de uma sql usando variáveis e Ranking
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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