Skip to content

Instantly share code, notes, and snippets.

@felclef
felclef / within-group-prog-count.sql
Created May 16, 2012 20:08
Simulating an partition-by-ordered-count (lol) in MySQL
-- 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