Created
May 16, 2012 20:08
-
-
Save felclef/2713550 to your computer and use it in GitHub Desktop.
Simulating an partition-by-ordered-count (lol) in MySQL
This file contains 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
-- olc: select id_quadro, user_hash from ( select iq.id_quadro, user_hash, if( @prev <> iq.id_quadro, @rownum := 1, @rownum := @rownum+1 ) as g_rank, @prev := iq.id_quadro from r7_inscricoes_quadros iq order by id_quadro, data_cadastro ) sq where g_rank <= 4 | |
-- the sample uses some database wich I have not luvd... yet... | |
select | |
id_quadro, | |
user_hash | |
from | |
( | |
select | |
iq.id_quadro, | |
user_hash, | |
if( @prev <> iq.id_quadro, @rownum := 1, @rownum := @rownum+1 ) as g_rank, | |
@prev := iq.id_quadro | |
from | |
r7_inscricoes_quadros iq | |
order by | |
id_quadro, data_cadastro | |
) sq | |
where | |
g_rank <= 4; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment